本文介绍了从路径创建蒙版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
不是CoreGraphics专家,我真的很感激一些帮助。
Not a CoreGraphics expert, I'd really appreciate some help.
我正在尝试从路径创建一个掩码。 (参见图片中的红色路径)。
I'm trying to create a mask from a path. (See red path in image).
我不喜欢红色路径,而是喜欢作为下面图像掩码的路径。
Instead of the red path, I'd like the path to be a mask to an image underneath.
真的可以用手了。提前致谢
Could really use a hand. Thanks in advance
- (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后的描边路径,保存图像并重复。
- Have UIView image on screen.
- Create UIImageView image with [UIColor clearColor] background color
- Use CoreGraphics to fill UIImageView with color
- Save UIImageView, then in TouchesMoved or UIPanGestureRecognizer, draw savedImage, Stroke Path after setting kCGContentBlendClear, save Image and repeat.
这篇关于从路径创建蒙版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!