我正在尝试为我的画笔应用纹理,但我真的很难弄清楚它是如何完成的。
这是我的输出图像。
我使用了一个 UIImage,它只是跟随屏幕上的触摸,但是当我更快地滑动它时,结果位于右侧“W”,而当我缓慢滑动时,结果位于左侧。
我尝试使用CGContextMoveToPoint
和CGContextAddLineToPoint
我不知道如何应用纹理。
是否可以使用 UIImage 作为描边纹理?
这是我的代码
UIImage * brushImageTexture = [UIImage imageNamed:@"brushImage.png"];
[brushImagetexture drawAtPoint:CGPointMake(touchCurrentPosition.x, touchVurrentPosition.y) blendMode:blendMode alpha:1.0f];
最佳答案
您需要沿着从前一个点到当前点的直线上的每个点手动绘制图像。
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];
}
关于iphone - objective-c : Using UIImage for Stroking,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8290680/