I’m using a bit of a workaround in order to successfully save an image with a mask (because you can’t render masks with CoreAction).
Here’s my code:
CGContextRef context = CGBitmapContextCreate(nil, cWidth, cHeight, bitsPerComponent, bytesPerRow, CGColorSpaceCreateDeviceRGB(), CGImageGetBitmapInfo(image));
//the mask:
CGContextClipToMask(context, CGRectMake(0,0,1280,935), self.image.image.CGImage);
//the image to mask:
CGContextDrawImage(context, CGRectMake(0, 0, 1280,935), viewImage.CGImage);
CGImageRef mergeResult = CGBitmapContextCreateImage(context);
saver = [[UIImage alloc] initWithCGImage:mergeResult];
So this works pretty well, the mask cuts out everything outside of its shape in the target image. This makes the surrounding area and background white. Rather than show white, I would like to show an image/color/pattern, etc. So I’d basically like to stack another image behind all that.
How can this be done? Thanks
Draw your background into the context first, then clip, then draw your image into the same context.