Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to have smooth sketch drawing on iPhone
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/5076622/iphone-smooth-sketch-drawing-algorithm">iPhone smooth sketch drawing algorithm</a> </p> </blockquote> <p>I want to develop a iPhone app that support sketch drawing.</p> <p>I used some codes like this in touchesMoved:</p> <pre><code>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(); </code></pre> <p>See:</p> <p><img src="https://i.stack.imgur.com/qV9iD.png" alt="curves not smooth"></p> <p>The curve is not smooth enough. </p> <p>I have tried Catmull-Rom Spline method using some codes form sourceforge.net/projects/curve/files/</p> <p>See:</p> <p><img src="https://i.stack.imgur.com/pPIWr.png" alt="smooth curves"></p> <p>This time the curve is much more smooth but it has 2 problems:</p> <ol> <li><p>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. </p></li> <li><p>The algorithm corrects corners too much so user cannot draw a star with sharp corners. </p></li> </ol> <p>I have a great desire to provide a very good drawing environment for user like "Sketch Book" app by Autodesk. (see image below)</p> <p>See:</p> <p><img src="https://i.stack.imgur.com/3DqHS.png" alt="very smooth"></p> <p>The app provides smooth curves and it also allows me to draw a star with sharp corners. </p> <p>How can I do that on iPhone? Which algorithm I can use to achieve good quality like "Sketch Book"? Any codes for my reference?</p> <p>Thanks!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload