从路径创建蒙版
问题描述:
不是CoreGraphics的专家,我非常感谢您的帮助。从路径创建蒙版
取而代之的是红色路径,我希望路径能够成为下方图像的遮罩。
真的可以用一只手。在此先感谢
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = YES;
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.view];
currentPoint.y -= 20;
UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 20.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
mouseMoved++;
if (mouseMoved == 10) {
mouseMoved = 0;
}
}
答
我想出了解决的办法是:
- 在屏幕上是否有UIView的形象。
- 与[的UIColor clearColor]背景颜色创建的UIImageView图像
- 使用CoreGraphics中填写的UIImageView颜色
- 保存的UIImageView,然后在TouchesMoved或UIPanGestureRecognizer,画savedImage,描边路径设置kCGContentBlendClear后,保存图片和重复。
答
一旦你创建的路径,使用CGContextReplacePathWithStrokedPath
将其转换为路径可以填充,以获得相同的结果轻抚路径。然后,您可以使用CGContextClip
将剪贴蒙版设置为此路径。
+0
走到从这走了一会儿。我知道你可能有正确的答案,我只需要更多的细节。 – Jordan 2012-01-21 12:16:43
你能解释一下吗?我在这里完全陷入了同样的问题 – Soumyajit 2013-10-07 05:39:45