How can I erase UIBezierPath lines drawn on a transparent view above an image?

我的未来我决定 提交于 2019-11-27 23:02:13

问题


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


回答1:


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?




回答2:


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



来源:https://stackoverflow.com/questions/7979937/how-can-i-erase-uibezierpath-lines-drawn-on-a-transparent-view-above-an-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!