iphone - 如何像粉笔一样画线?

标签 iphone ios line draw

我想画线,就像粉笔一样。并且线条的边缘是微弱的。就像用粉笔在黑板上画画一样。

我如何得到这个? 现在,我用图像画了线,但它看起来不像是在黑板上画的,因为线并不模糊。 请给我一些建议。

这是我的代码:

    for (NSDictionary *dictStroke in self.arrayStrokes)
    {
        NSArray *arrayPointsInstroke = [dictStroke objectForKey:@"points"];
        //UIColor *color = [dictStroke objectForKey:@"color"];

    UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"point.png"]];

        float size = [[dictStroke objectForKey:@"size"] floatValue];
        [color setStroke];      // equivalent to both setFill and setStroke

        // draw the stroke, line by line, with rounded joints
        UIBezierPath* pathLines = [UIBezierPath bezierPath];
        CGPoint pointStart = CGPointFromString([arrayPointsInstroke objectAtIndex:0]);
        [pathLines moveToPoint:pointStart];
        for (int i = 0; i < (arrayPointsInstroke.count - 1); i++)
        {
            CGPoint pointNext = CGPointFromString([arrayPointsInstroke objectAtIndex:i+1]);
            [pathLines addLineToPoint:pointNext];
        }
        pathLines.lineWidth = size;
        pathLines.lineJoinStyle = kCGLineJoinRound;
        pathLines.lineCapStyle = kCGLineCapRound;
        [pathLines stroke];

        arraynum++;
    }

最佳答案

尝试使用带有斑马线的图案图像。这会给你带来像粉笔书写一样的效果。

brushPattern = [[UIColor alloc]initWithPatternImage: [UIImage imageNamed:@"pattern.jpg"]];

- (void)drawRect:(CGRect)rect
{
    [brushPattern setStroke];
    [myPath strokeWithBlendMode:kCGBlendModeNormal alpha:1.0]; // myPath - points to be drawn    
}

关于iphone - 如何像粉笔一样画线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10629579/

相关文章:

jQuery 和移动浏览器的兼容性?

iPhone hitTest 旋转后损坏

ios - CollectionView sizeForitemAt 方法不适用于 ios 9

matlab - MATLAB 中不可能有可点击的透明线?

iphone - 以编程方式创建图像的缩略图

objective-c - 有什么方法可以询问方法的名称吗?

ios - Nil 与预期的参数类型 'String' 不兼容

javascript - iOS 14 API WKScriptMessageHandlerWithReply 如何与 iOS 中的 JavaScript 通信?

objective-c - 绘制虚线和实线

c++ - 如何计算两条线的交点