Erase after drawing with CGContext

I am trying to make a simple drawing application for the iPad where you can draw a picture, and I use the CGContext material for this, but the way I originally planned to do the erasing was just to draw the material using white ... except that I just I realized today that it does not work when you draw on another image, because then when you β€œerase” you also β€œclear” the background image.

Is there a way to support the actual erasure?

Thanks!

+6
source share
2 answers

Display the user's drawing in the layer above the image. Then erasing is as simple as drawing a transparent patch on a drawing layer to allow the pixels of the image below it to show.

+4
source

I also need erasing functionality. Based on @Jeremy's answer, here is what worked for me:

CGContextRef cgref = UIGraphicsGetCurrentContext(); if(erase == TRUE) // Erase to show background { CGContextSetBlendMode(cgref, kCGBlendModeClear); } else // Draw with color { CGContextSetBlendMode(cgref, kCGBlendModeNormal); } 
+19
source

Source: https://habr.com/ru/post/887634/


All Articles