iPhone 流畅的草图绘制算法 [英] iPhone smooth sketch drawing algorithm

查看:23
本文介绍了iPhone 流畅的草图绘制算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 iPhone 上开发一个素描应用程序.我让它工作了,但不像这里看到的那么漂亮

I am working on a sketching app on the iPhone. I got it working but not pretty as seen here

我正在寻找任何建议来平滑绘图基本上,我所做的是当用户将手指放在我调用的屏幕上时

And I am looking for any suggestion to smooth the drawing Basically, what I did is when user places a finger on the screen I called

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 

然后我用

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

当用户从屏幕上离开一个手指时,我调用了

and when the user lefts a finger from the screen, I called

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

然后我使用

NSMutableArray *points = [collectedArray points];   

CGPoint firstPoint;
[[points objectAtIndex:0] getValue:&firstPoint];

CGContextMoveToPoint(context, firstPoint.x, firstPoint.y);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineJoin(context, kCGLineJoinRound);

for (int i=1; i < [points count]; i++) {
    NSValue *value = [points objectAtIndex:i];
    CGPoint point;
    [value getValue:&point];    
    CGContextAddLineToPoint(context, point.x, point.y);

} 

CGContextStrokePath(context);
UIGraphicsPushContext(context);

现在我想将绘图改进为更像素描本"应用程序

And now I want to improve the drawing tobe more like "Sketch Book" App

我认为重新排列数组中的所有点与信号处理算法有关,但我不确定.任何帮助将非常感激.

I think there is something to do with signal processing algorithm to rearrange all the points in the array but I am not sure. Any Help would be much appreciated.

提前致谢:)

推荐答案

平滑这样的曲线的最简单方法是使用贝塞尔曲线而不是直线段.有关这背后的数学原理,请参阅这篇文章(在这个答案),它描述了如何计算平滑通过的曲线所需的曲线通过多个点.

The easiest way to smooth a curve like this is to use a Bezier curve instead of straight line segments. For the math behind this, see this article (pointed to in this answer), which describes how to calculate the curves required to smooth a curve that passes through multiple points.

我相信 Core Plot 框架 现在能够平滑曲线的图,所以你可以看看那里用来实现这种平滑的代码.

I believe that the Core Plot framework now has the ability to smooth the curves of plots, so you could look at the code used there to implement this kind of smoothing.

这一切都没有什么神奇之处,因为这些平滑例程速度快且相对容易实现.

There's no magic to any of this, as these smoothing routines are fast and relatively easy to implement.

这篇关于iPhone 流畅的草图绘制算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆