Is it possible to make CGContextClipToMask ignore the grayscale values of the mask image and work as if it was plain black and white?
I have a grayscale image, and when I use it as a mask gray color are interpreted as an alpha channel. This is fine except for a point where I need to completely mask those pixels that are not transparent.
Short example:
UIImage *mask = [self prepareMaskImage];
UIGraphicsBeginImageContextWithOptions(mask.size, NO, mask.scale); {
// Custom code
CGContextClipToMask(UIGraphicsGetCurrentContext(), mask.size, mask.CGImage);
// Custom code
}
Is it possible to adapt this code to achieve my goal?
Long story short: I need to make a transparent grayscale image become transparent where it originally was and completely black where it’s solid-colored.
Interesting problem! Here’s code that does what I think you want in a simple sample project. Similar to above but handles scale properly. Also has option to retain the alpha in the mask image if you want. Quick hacked together test that seems to work.