So I'm applying an image mask to a UIView layer with the following code:
CALayer *maskLayer = [CALayer layer];
UIImage *maskImage = self.image.image;
maskLayer.contents = (id)maskImage.CGImage;
maskLayer.frame = CGRectMake(0.0, 0.0,1235, 935);
self.bgView.layer.mask = maskLayer;
Everything is fine and dandy, the mask covers the view content and works. However, I am trying to take a screenshot to let the user save the image. I'm using the following code:
UIGraphicsBeginImageContext(captureFrame.size);
[self.bgView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
The frame is fine, and its saving to the photo library. The only problem is that the mask applied to the layer does not show up in the JPG. I have also tried nesting my bgView into another UIView, and then trying to renderInContext:
that, but its the same thing. It simply appears as if the mask is not being applied in the final JPG.
Any ideas? Thank you.