iphone - objective-c : Using UIImage for Stroking

标签 iphone objective-c ios ipad core-graphics

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

这是我的输出图像。

我使用了一个 UIImage,它只是跟随屏幕上的触摸,但是当我更快地滑动它时,结果位于右侧“W”,而当我缓慢滑动时,结果位于左侧。

enter image description here

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

是否可以使用 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/

相关文章:

ios - iTunes connect - 我在哪里可以看到 TestFlight 构建的崩溃报告?

iphone - 为什么我的 UItableView 不水平滚动,而我将 ContentSize 设置得更大?

iphone - 以编程方式更改 UIKit 对象 anchor ?

ios - UICollectionView 和 UIView 变成 UIScrollView

iphone - Adobe Flash 构建器 iOS 应用程序与 native iOS 应用程序

iphone - 您应该使用 'isEqual' 还是 '=='?

objective-c - UITapGestureRecognizer导致应用崩溃

ios - Animate Controls 因 UINavigationBar 的更改而下降

ios - 如何通过 ios 中的继承访问私有(private)声明的属性

android - WordPress 主题中的简单 Android 与 iOS 检测