如何擦除在图像上方的透明视图上绘制的 UIBezierPath 线?

发布于 2024-12-13 09:42:03 字数 458 浏览 0 评论 0原文

我正在创建一个类似白板应用程序的应用程序。我有一张动态图像。图像有多种颜色。我想在该图像上画一条与白板相同的线,所以我在上面重叠了一个透明视图。现在我正在用选定的颜色绘制线条,效果非常好。

现在的问题是,当我尝试在触摸屏幕时擦除线条时,它应该显示像橡皮擦一样的效果。如果我有一些固定颜色(如白色)背景,那么为了擦除线条,我可以用背景颜色绘制一条线,但这里我有透明的视图背景,所以我不能这样做。

我尝试用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幽蝶幻影 2024-12-20 09:42:03

如果背景中有图像,并且该图像的大小和原点与白板绘图画布相同,则可以尝试使用背景图像作为颜色模式来绘制“擦除”线:

[[UIColor colorWithPatternImage:backgroundImage] set];

其中 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:

[[UIColor colorWithPatternImage:backgroundImage] set];

Where backgroundImage is the UIImage 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?

还给你自由 2024-12-20 09:42:03

您可以使用混合模式。使用 CGBlendMode..Clear 文档

You can use blend mode. Use CGBlendMode..Clear Document

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文