目标C:使用UIImage进行描边操作 [英] Objective C: Using UIImage for Stroking

查看:162
本文介绍了目标C:使用UIImage进行描边操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的画笔应用纹理,但我真的很难弄清楚它是如何完成的。

I am trying to apply a texture for my brush but i'm really having a hard time figuring how it is done.

这是我输出的图像。

我使用的UIImage只是跟在屏幕上的触摸,但是当我快速滑动时,结果在右侧W,而在左侧则是当我慢慢滑动时的结果。

I used an UIImage that just follows the touch on the screen but when i swipe it faster the result is on the right side "W", and on the left side that's the result when i swipe it slow.

我尝试使用 CGContextMoveToPoint CGContextAddLineToPoint 我不知道如何应用纹理。

i tried using the CGContextMoveToPoint and CGContextAddLineToPoint i don't know how apply the texture.

是否可以将UIImage用于笔触纹理?

Is it possible to use UIImage for the stroke texture?

这是我的代码

    UIImage * brushImageTexture = [UIImage imageNamed:@"brushImage.png"]; 
    [brushImagetexture drawAtPoint:CGPointMake(touchCurrentPosition.x, touchVurrentPosition.y) blendMode:blendMode alpha:1.0f];


推荐答案

您需要在每个点手动绘制图像从前一点到当前点的行。

You need to manually draw the image at each point along the line from the previous point to the current point.

CGPoint vector = CGPointMake(currentPosition.x - lastPosition.x, currentPosition.y - lastPosition.y);
CGFloat distance = hypotf(vector.x, vector.y);
vector.x /= distance;
vector.y /= distance;
for (CGFloat i = 0; i < distance; i += 1.0f) {
    CGPoint p = CGPointMake(lastPosition.x + i * vector.x, lastPosition.y + i * vector.y);
    [brushImageTexture drawAtPoint:p blendMode:blendMode alpha:1.0f];
}

这篇关于目标C:使用UIImage进行描边操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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