-
-
Save guidedways/9262ddf947d846d6830d25ed525f959f to your computer and use it in GitHub Desktop.
Masking a UIImage with a mask UIImage in iOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (UIImage*) maskImageWithMask:(UIImage *) mask | |
{ | |
CGImageRef imageReference = self.CGImage; | |
CGImageRef maskReference = mask.CGImage; | |
CGImageRef imageMask = CGImageMaskCreate(CGImageGetWidth(maskReference), | |
CGImageGetHeight(maskReference), | |
CGImageGetBitsPerComponent(maskReference), | |
CGImageGetBitsPerPixel(maskReference), | |
CGImageGetBytesPerRow(maskReference), | |
CGImageGetDataProvider(maskReference), | |
NULL, // Decode is null | |
YES // Should interpolate | |
); | |
CGImageRef maskedReference = CGImageCreateWithMask(imageReference, imageMask); | |
CGImageRelease(imageMask); | |
UIImage *maskedImage = [UIImage imageWithCGImage:maskedReference]; | |
CGImageRelease(maskedReference); | |
return maskedImage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Original was leaking memory