使用图案颜色来模拟画笔纹理 [英] Stroking paths using a pattern color to simulate brush texture

查看:102
本文介绍了使用图案颜色来模拟画笔纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个手指画应用程序,我很难给我的画笔一个很好的画笔般的感觉和纹理。

I am making a finger painting app and I am having a hard time giving my brush a nice brush-like feel and texture.

我有这个代码: / p>

I have this code:

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

但我的输出如下:

but my output is like this:

我的画笔的纹理是平铺的。

The texture of my brush is tiled. How can I make it fit to the stroke Size and stop the tiling of the image?

推荐答案

这里我找到了一个解决方案! / p>

Here i found a solution!

    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];
    }

这篇关于使用图案颜色来模拟画笔纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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