I am trying to erase an image with my touch in iOS. By setting the blend mode to kCGBlendModeClear I am able to do this – but only with hard edges. I could draw my stroke with varying line widths and alphas, but it appears that CGContextSetAlpha does not have an effect with kCGBlendModeClear.
How do I go about this?
I would use a transparency layer compositing with
kCGBlendModeDestinationOut(Da * (1 - Sa), Dc * (1 - Sa).) Something like this:Note that you should also save and restore the gstate (
CGContextSaveGState()/CGContextRestoreGState()) before/after the transparency layer to ensure that the blend mode and any other gstate changes do not persist.Note: This is brain-compiled and it’s possible that transparency layers don’t play nice with all blend modes. If so, try drawing the path/image into a second bitmap context, then drawing the contents of that context with the above blend mode.
You can also experiment with other blend modes for different effects.