使用 Quartz 2D 绘制线条且 alpha 属性 < 时出现问题iPhone 上的 1.0

发布于 2024-09-01 20:52:29 字数 1470 浏览 5 评论 0 原文

我用这段代码在我的应用程序中绘制。所以我有问题,如果我用 alpha 属性 = 1 绘制。它非常好,但如果我更改 alpha 属性 = 0.2 那么我的油漆就不好。如何使 alpha 属性 = 0.2 变得更好。

http://www.flickr.com/photos/9601621@N05/page1/< /a>

用 alpha = 1 绘制:很好 用 alpha = 0.2 绘制:这很糟糕

    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
 if ([self.view superview] && (headerView.frame.origin.y == -30)) {
  mouseSwiped = YES;

  UITouch *touch = [touches anyObject]; 
  CGPoint currentPoint = [touch locationInView:self.view];
  currentPoint.y -= 20;



  UIGraphicsBeginImageContext(self.view.frame.size);

  CGContextRef context = UIGraphicsGetCurrentContext();

  [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
  CGContextSetLineCap(context, kCGLineCapRound);
  CGContextSetLineWidth(context, currentBrushProperty.brushSize);
  CGContextSetRGBStrokeColor(context, [self red], [self green], [self blue], currentBrushProperty.brushTransparency);
  CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);

  CGContextBeginPath(context);
  CGContextMoveToPoint(context, lastPoint.x, lastPoint.y);
  CGContextAddLineToPoint(context, currentPoint.x, currentPoint.y);

  CGContextStrokePath(context);
  drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();

  lastPoint = currentPoint;

 }}

This code I use to draw in my app. So I have problem, if I draw with alpha property = 1. It is very good but if I change alpha property = 0.2 then my paint is not good. How do I make for better with alpha property = 0.2.

http://www.flickr.com/photos/9601621@N05/page1/

Draw with alpha = 1: It is good
Draw with alpha = 0.2: It is bad

    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
 if ([self.view superview] && (headerView.frame.origin.y == -30)) {
  mouseSwiped = YES;

  UITouch *touch = [touches anyObject]; 
  CGPoint currentPoint = [touch locationInView:self.view];
  currentPoint.y -= 20;



  UIGraphicsBeginImageContext(self.view.frame.size);

  CGContextRef context = UIGraphicsGetCurrentContext();

  [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
  CGContextSetLineCap(context, kCGLineCapRound);
  CGContextSetLineWidth(context, currentBrushProperty.brushSize);
  CGContextSetRGBStrokeColor(context, [self red], [self green], [self blue], currentBrushProperty.brushTransparency);
  CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);

  CGContextBeginPath(context);
  CGContextMoveToPoint(context, lastPoint.x, lastPoint.y);
  CGContextAddLineToPoint(context, currentPoint.x, currentPoint.y);

  CGContextStrokePath(context);
  drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();

  lastPoint = currentPoint;

 }}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最丧也最甜 2024-09-08 20:52:29

你的问题是你正在绘制一系列半透明的圆圈 - 每个记录触摸的地方都有一个。最简单的解决方案可能是使用 100% Alpha 进行绘制,然后将彩色区域的 Alpha 调整回您想要的 Alpha。

Your problem is that you are drawing a series of semi-transparent circles - one for each place at which the touch is registered. The easiest solution might be to draw with 100% alpha then adjust the alpha of the coloured region back to the alpha you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文