I'm drawing to a CGContext and using a CGImageRef-based mask:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClipToMask(context, rect, _firstMaskImageRef);
CGContextSetFillColorWithColor(context, color);
CGContextFillRect(context, rect);
I have a second mask that I then want to switch to:
CGContextClipToMask(context, rect, _secondMaskImageRef);
CGContextSetFillColorWithColor(context, color); // color has changed FWIW
CGContextFillRect(context, rect); // as has rect
But, this intersects the two masks instead of replacing the first.
How do you (if you can) clear out or reset the clipping mask for a CGContext?
You can save the graphics state before you set the clipping mask, and then reset it afterwards, like this:
CGContextSaveGState (context);
...Set your first clipping mask, fill it, etc.
CGContextRestoreGState (context);
...Do other stuff
To reset the clipping mask, use:
CGContextResetClip(context);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With