如何擦除在图像上方的透明视图上绘制的 UIBezierPath 线?
我正在创建一个类似白板应用程序的应用程序。我有一张动态图像。图像有多种颜色。我想在该图像上画一条与白板相同的线,所以我在上面重叠了一个透明视图。现在我正在用选定的颜色绘制线条,效果非常好。
现在的问题是,当我尝试在触摸屏幕时擦除线条时,它应该显示像橡皮擦一样的效果。如果我有一些固定颜色(如白色)背景,那么为了擦除线条,我可以用背景颜色绘制一条线,但这里我有透明的视图背景,所以我不能这样做。
我尝试用 alpha = 0 的颜色绘制一条线,但这不会反映任何内容,因为该线也是透明颜色。
我正在添加我的绘制矩形方法。
for (UIBezierPath *path in aryDrawPath) {
[[UIColor redColor] set];
[path stroke];
}
任何人都可以帮我解决这个问题吗?
多谢
I am creating an app like whiteboard application. I have one dynamic image. Image has multiple colors. I want to draw line on that Image same as whiteboard so I had overlap a Transparent View on that. Now I am drawing line with chosen color that's working very well.
Now the problem is when I try to erase the line when touch on screen it should show effects like eraser. If I has some fixed color (like white) background then for erasing line I can draw a line with background color but here I have transparent background of view so I cant do that.
I tried with draw a line with color has alpha = 0 but this doesn't reflect anything as the line is also transparent color.
I am adding in my draw rect method.
for (UIBezierPath *path in aryDrawPath) {
[[UIColor redColor] set];
[path stroke];
}
Can any body help me to solve this problem.
Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果背景中有图像,并且该图像的大小和原点与白板绘图画布相同,则可以尝试使用背景图像作为颜色模式来绘制“擦除”线:
其中
backgroundImage
是您在其上绘制的UIImage
。这将用下面的图像覆盖您绘制的线条,因此看起来它们被删除了。不过,这似乎有点老套?
If you have an image in the background, and the image is the same size and origin as your whiteboard drawing canvas, you could try drawing your "erase" lines using the background image as a colour pattern:
Where
backgroundImage
is theUIImage
that you are drawing on top of.This will overpaint your drawn lines with the image underneath, so it will appear that they are erased. It seems a bit hacky, though?
您可以使用混合模式。使用 CGBlendMode..Clear 文档
You can use blend mode. Use CGBlendMode..Clear Document