Q:

How to save masked image to camera roll or to share social media

I can mask an image perfectly after mask is done perfectly when I am trying to save the masked image, it is saving as normal image without mask.or can some post the code to save with mask Please help me. Here's the code -
- (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage {

CGImageRef imager = [image CGImage];
CGImageRef maskRef = [maskImage CGImage];
CGImageRef actualMask = CGImageMaskCreate(CGImageGetWidth(maskRef),
                                          CGImageGetHeight(maskRef),
                                          CGImageGetBitsPerComponent(maskRef),
                                          CGImageGetBitsPerPixel(maskRef),
                                          CGImageGetBytesPerRow(maskRef),
                                          CGImageGetDataProvider(maskRef), NULL, false);
CGImageRef masked = CGImageCreateWithMask(imager, actualMask);
return [UIImage imageWithCGImage:masked];

}
  - (IBAction)mask:(id)sender
{
imageView.image = [self maskImage:imageView.image withMask:[UIImage imageNamed:@"mask"]];
   }

- (IBAction)shareorsave:(id)sender {

NSArray *itemsToShare =@[imageView.image];

UIActivityViewController *activityVC =[[UIActivityViewController alloc]initWithActivityItems:itemsToShare applicationActivities:nil];

[self presentViewController:activityVC animated:YES completion:nil];
 }
@end

A:

I'm not sure if you still got the thing figured it out but I faced the same problem. Try to render the imageView's layer as folllows :
 if([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
        UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, [UIScreen mainScreen].scale);
    else
        UIGraphicsBeginImageContext(self.view.frame.size);

   [imageView.layer renderInContext:UIGraphicsGetCurrentContext()];

   UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
   UIGraphicsEndImageContext();

Then add in itemsToShare the newImage.
Don't forget to add QuartzCore.framework and
#import  <QuartzCore/QuartzCore.h> 

Hope that helps!

