iPhone平滑的草图绘制算法 [英] iPhone smooth sketch drawing algorithm

查看:105
本文介绍了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 

然后我收集数组中的单个触摸

then I collect a single touch in an array with

- (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);

现在我想改善绘图更像是Sketch BookApp
< img src =https://i.stack.imgur.com/zIfjJ.pngalt =在此处输入图像说明>

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天全站免登陆