Question

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

Was it helpful?

Solution

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?

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top