iPhone:如何在TouchesMoved事件上制作透明图像?

时间:2011-12-26 02:28:37

标签: iphone image graphics transparency cgcontext

我已经尝试了kCGBlendModeXOR,但在透明度之后变黑了。

这是我完成的代码,但不是我想要的。

  UITouch *touch = [touches anyObject];  
  CGPoint currentPoint = [touch locationInView:self.view];
  CGPoint lastPoint = [touch locationInView: [UIApplication sharedApplication].keyWindow];
  UIGraphicsBeginImageContext(self.view.frame.size);
  CGRect rect = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
  [imageView_skype.image drawInRect:rect];
  CGContextRef context = UIGraphicsGetCurrentContext();

  CGContextSetLineCap(context, kCGLineCapRound);
  CGContextSetLineWidth(context, 36.0);
  CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
  CGContextSetAlpha(context,0.10);

  CGContextSetBlendMode(context, kCGBlendModeXOR);

  CGContextBeginPath(context);

  CGContextMoveToPoint(context, lastPoint.x, lastPoint.y);
  CGContextAddLineToPoint(context, currentPoint.x, currentPoint.y);
  CGContextStrokePath(context);
  imageView_skype.image = UIGraphicsGetImageFromCurrentImageContext();

1 个答案:

答案 0 :(得分:0)

你可以使用面具来做到这一点

http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_images/dq_images.html

在触摸移动事件中绘制一个仅黑白的蒙版图像

并屏蔽原始图像