Hi, in my application i've used a UIImagePickerController to take a photo, and after i took the photo, i cant't draw it using UIImageView because i want draw on it some lines with my finger;
To this end I have written in draw rect methods this code:
(void)drawRect:(CGRect)rect {
[self.myimage drawInRect: rect]; //Disegno rettangolo del tag CGContextRef myContext = UIGraphicsGetCurrentContext(); CGContextSetRGBStrokeColor(myContext, 0.5, 0.5, 0.5, 1.0); CGContextSetLineWidth(myContext, 3.0f); CGContextAddPath(myContext, pathTouches); CGContextStrokePath(myContext);
}
and in touchesMoved:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint locationInView = [touch locationInView:self];
// Draw a connected sequence of line segments
CGPoint addLines[] =
{
//....
//some lines
};
CGMutablePathRef newPath = CGPathCreateMutable();
CGPathRelease(pathTouches);
pathTouches = CGPathCreateMutableCopy(newPath);
CGPathRelease(newPath);
CGPathAddLines(pathTouches, NULL, addLines, sizeof(addLines)/sizeof(addLines[0]));
[self setNeedsDisplay];
}
Is correct to call [self setNeedsDisplay]; every time that i move my finger or there is a better way to do this?
thanks