Dans mon application, j'ai utilisé un UIImagePickerController
pour prendre une photo, et après avoir pris la photo, je ne peux pas la dessiner en utilisant UIImageView
car je veux tracer quelques lignes dessus avec mon doigt.Dessin UIImage dans CurrentContext
A cette fin, je l'ai écrit dans les méthodes draw rect ce 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);
}
et 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];
}
Est-il correct d'appeler [self setNeedsDisplay];
chaque fois que je déplace mon doigt, ou il est une meilleure façon de faire cela?
Salut, merci pour votre code, j'ai essayé de dessiner sur un simple uiview sur mon application, mais ne fonctionne pas ... pouvez-vous m'aider ?? merci – ghiboz
@Rahul Vyas Pouvez-vous m'aider à résoudre ce problème: http://stackoverflow.com/q/9850772/434898 –