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

LINUX Move and copy files using SSH

PHP Predefined Variables

Java : Variables Declaring