views:

44

answers:

1

In one of my apps, am trying to erase/transparent stroke a part of UIImage which am drawing using CoreGraphics framework (CGContextRef etc..). Well in the process I am able to clear the drawing in one shot by calling "removeAllObjects" message, but I was not able to figure out, how to erase a part of the drawing image. Gosh!! I sat the whole day but still no results, now its killing me. Please guys help me out from here. In short, my requirement is something like an eraser which can erase a part of of my drawing image. Appreciate your help!!

A: 

Generally, CGContexts are additive-only canvases--that is you can only add more paint, not remove any existing paint that you've put on them. If your canvas was white to start with, you can paint over with white to fake and erase operation.

A simple solution would be to manually clear out the areas of the backing bitmap are being erasing.

A complex solution is to store all the painting operations that the user has entered and deform them as a result of the erase operation (this will also make adding an undo mode simple)

Note: There is the CGContextClearRect function, but it generally only works as expected on bitmap contexts.

rpetrich
Manab
Or your first solution to fake and erase, I can try. To be honest here i dont have any prior knowledge on CGContextClearRect, so need to google out more on that.
Manab
Your best bet would be to use `CGBitmapContextCreate` and supply your own backing buffer--then you can modify it directly using your own erasing code
rpetrich