IOS How to mask image

+ (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage {
   
    CGImageRef maskRef = maskImage.CGImage;
   
    CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef),
                                        CGImageGetHeight(maskRef),
                                        CGImageGetBitsPerComponent(maskRef),
                                        CGImageGetBitsPerPixel(maskRef),
                                        CGImageGetBytesPerRow(maskRef),
                                        CGImageGetDataProvider(maskRef), NULL, false);
   
    CGImageRef masked = CGImageCreateWithMask([image CGImage], mask);
   
    CGImageRelease(mask);
    CGImageRelease(maskRef);
    return [UIImage imageWithCGImage:masked];
   
}

Comments

Popular posts from this blog

Java : Variables Declaring

SQL Self JOIN