使用Quartz 2D绘制线条时使用alpha属性< iPhone上的1.0

时间:2010-05-14 02:38:12

标签: iphone graphics quartz-graphics quartz-2d

我用这个代码在我的应用程序中绘制。所以我有问题,如果我绘制alpha属性= 1.这是非常好的,但如果我改变alpha属性= 0.2然后我的油漆不好。如何使用alpha property = 0.2来实现更好的效果。

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

用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;

 }}

1 个答案:

答案 0 :(得分:0)

您的问题是您正在绘制一系列半透明圆圈 - 每个圆圈都有一个用于注册触摸的位置。最简单的解决方案可能是使用100%alpha进行绘制,然后将彩色区域的alpha调整回所需的alpha值。