Possible Duplicate:
how to create an application which allows user to free hand drawing?
I am trying to implement free hand writing on a view. I used some of the existing code, which is working well when user is writing very slow, where as if the user writes very fast it s not recognizing all the points(what ever the points are touched by the user). my sample code is here
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = YES;
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self];
currentPoint.y -= 20;
UIGraphicsBeginImageContext(self.bounds.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
if (mode == DrawingModePen) {
NSLog(@"drawing");
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [_drawingPenColor CGColor]);
}
else {
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [[UIColor clearColor] CGColor]);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextClearRect (UIGraphicsGetCurrentContext(), CGRectMake(lastPoint.x, lastPoint.y, 20, 20));
CGContextStrokePath(UIGraphicsGetCurrentContext());
NSLog(@"clearing");
}
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
mouseMoved++;
if (mouseMoved == 10) {
mouseMoved = 0;
}
}
是否有其他办法执行? 我看到了GLPaint由pple提供。 在我的记忆中发出记忆警告,这也没有什么用处。