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

查看:23
本文介绍了如何擦除在图像上方透明视图上绘制的 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.

我正在添加我的 draw 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 是您在其上绘制的 UIImage.

Where backgroundImage is the UIImage that you are drawing on top of.

这会将您绘制的线条与下方的图像重叠,因此它们看起来会被擦除.不过,这似乎有点 hacky?

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天全站免登陆