gpt4 book ai didi

iphone - 多色线描

转载 作者:行者123 更新时间:2023-11-28 22:26:02 27 4
gpt4 key购买 nike

我正在创建一个绘图应用程序。其中一项功能是多色线条图。它应该像用户触摸屏幕并在其上画一条线一样工作。线条的颜色平滑地变化。像那样http://www.examples.pavelgatilov.com/Screen%20Shot%202013-09-22%20at%208.37.42%20PM.png

我尝试了几种方法,但并不走运。

我的画线方法如下:

- (void) drawLineFrom:(CGPoint)from to:(CGPoint)to width:(CGFloat)width
{
self.drawColor = toolColor;
UIGraphicsBeginImageContext(self.frame.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextScaleCTM(ctx, 1.0f, -1.0f);
CGContextTranslateCTM(ctx, 0.0f, -self.frame.size.height);
if (drawImage != nil) {
CGRect rect = CGRectMake(0.0f, 0.0f, self.frame.size.width, self.frame.size.height);
CGContextDrawImage(ctx, rect, drawImage.CGImage);
}
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextSetLineWidth(ctx, width);
CGContextSetStrokeColorWithColor(ctx, self.drawColor.CGColor);
CGContextMoveToPoint(ctx, from.x, from.y);
CGContextAddLineToPoint(ctx, to.x, to.y);
CGContextStrokePath(ctx);
CGContextFlush(ctx);
drawImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
drawLayer.contents = (id)drawImage.CGImage;
}

谢谢你的帮助

最佳答案

具体取决于什么颜色、它们如何变化以及您想要什么效果/线路转弯会发生什么,您可能需要查看以下组合:

  • CGContextDrawLinearGradient 对用户绘制的路径进行屏蔽。
  • colorWithPatternImage:
  • CGContextDrawLinearGradient 在另一层后面绘制,并使用 kCGBlendModeClear
  • 将透明度绘制到顶层

关于iphone - 多色线描,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18946965/

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