如何擦除在图像上方的透明视图上绘制的UIBezierPath线? [英] How can I erase UIBezierPath lines drawn on a transparent view above an image?

查看:126
本文介绍了如何擦除在图像上方的透明视图上绘制的UIBezierPath线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个像白板应用程序的应用程序。我有一个动态图像。图像有多种颜色。我想在该图像上绘制与白板相同的线,因此我重叠了透明视图。现在我正在使用选择好的颜色画线。

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.

我试着画一条颜色的线有alpha = 0但这并没有反映任何东西,因为这条线也是透明的颜色。

I tried with draw a line with color has alpha = 0 but this doesn't reflect anything as the line is also transparent color.

我在画画中添加rect方法。

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.

非常感谢

推荐答案

如果背景中有图像,图像是与白板绘图画布相同的大小和原点,您可以尝试使用背景图像作为颜色图案绘制擦除行:

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:

[[UIColor colorWithPatternImage:backgroundImage] set];

其中 backgroundImage 是<$ c $你正在绘制的c> UIImage 。

这将使用下面的图像覆盖您绘制的线条,因此它们将被删除。但是看起来有点笨拙?

This will overpaint your drawn lines with the image underneath, so it will appear that they are erased. It seems a bit hacky, though?

这篇关于如何擦除在图像上方的透明视图上绘制的UIBezierPath线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆