gpt4 book ai didi

objective-c - 使用图案颜色的描边路径来模拟画笔纹理

转载 作者:太空狗 更新时间:2023-10-30 03:43:09 27 4
gpt4 key购买 nike

我正在制作一个手指绘画应用程序,但我很难让我的画笔具有漂亮的画笔般的手感和质感。

我有这个代码:

    UIColor * brushTexture = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Brush_Black.png"]]; 
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), brushTexture.CGColor);

但我的输出是这样的:
Image of Mouse

我画笔的纹理是平铺的。如何使其适合笔画大小并停止图像的平铺?

最佳答案

在这里我找到了解决方案!

    UIImage *texture = [UIImage imageNamed:"brush.png"]    
CGPoint vector = CGPointMake(currentPoint.x - endPoint.x, currentTPoint.y - endPoint.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(endPoint.x + i * vector.x, endPoint.y + i * vector.y);
[texture drawAtPoint:p blendMode:blendMode alpha:0.5f];
}

关于objective-c - 使用图案颜色的描边路径来模拟画笔纹理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8237240/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com