Possible Duplicate:
iPhone smooth sketch drawing algorithm
I want to develop a iPhone app that support sketch drawing.
I used some codes like this in touchesMoved:
UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 1.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), points.pointB.x, points.pointB.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), points.pointA.x, points.pointA.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
See:
The curve is not smooth enough.
I have tried Catmull-Rom Spline method using some codes form sourceforge.net/projects/curve/files/
See:
This time the curve is much more smooth but it has 2 problems:
Catmull-Rom Spline uses many cubic bezier curve segments and a quadratic bezier curve segment to form a curve. The quadratic bezier curve segment cannot be determine when the touch end. And I cannot plot quadratic segment before a user removing his finger from screen. I can only plot cubic segments when user is drawing so he will feel some delay. The curve lag behind he finger when the finger move fast.
The algorithm corrects corners too much so user cannot draw a star with sharp corners.
I have a great desire to provide a very good drawing environment for user like "Sketch Book" app by Autodesk. (see image below)
See:
The app provides smooth curves and it also allows me to draw a star with sharp corners.
How can I do that on iPhone? Which algorithm I can use to achieve good quality like "Sketch Book"? Any codes for my reference?
Thanks!!