2011-11-23 9 views
5

我正在做一個手指畫應用程序,我很難給我的畫筆提供一個很好的畫筆般的感覺和紋理。使用圖案顏色來描繪路徑來模擬畫筆紋理

我有這樣的代碼:

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

,但我的輸出是這樣的:
Image of Mouse

我刷的紋理瓷磚。如何使它適合筆畫大小並停止圖像的平鋪?

+0

您是否發現過答案? –

+0

你有沒有找到解決方案? – DivineDesert

+0

@布魯諾在那裏!我回答了!希望它會有所幫助! – SeongHo

回答

7

在這裏我找到了解決方案!

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

而這方面的表現還不錯? – jjxtra

+1

你能提供一個樣本,看看是什麼樣子?考慮到這是一年前的事情,我知道我需要很多東西,但我也對這個領域感興趣,並且正在評估幾篇論文/帖子的在線實施。 – kurtzbot