Erasing after drawing with CGContext

霸气de小男生 提交于 2020-01-22 05:56:08

问题


I'm trying to do a simple drawing app for the iPad where you can draw on a picture, and I'm using CGContext stuff to do it but the way I originally planned on handling erasing was to just draw over stuff with white...except I just realized today that it doesn't work when you're drawing onto another image because then when you "erase" you'll also "erase" the background image as well.

Is there any way to support actual erasing?

Thanks!


回答1:


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




回答2:


I also needed 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);
}


来源:https://stackoverflow.com/questions/5939096/erasing-after-drawing-with-cgcontext

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