Stroking paths using a pattern color to simulate brush texture

谁说我不能喝 提交于 2019-12-03 04:40:57

问题


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

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?


回答1:


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


来源:https://stackoverflow.com/questions/8237240/stroking-paths-using-a-pattern-color-to-simulate-brush-texture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!