Skip to content

Instantly share code, notes, and snippets.

@mundstein
Created October 29, 2012 11:34
Show Gist options
  • Save mundstein/3973082 to your computer and use it in GitHub Desktop.
Save mundstein/3973082 to your computer and use it in GitHub Desktop.
Great simple masking image routine for core graphics
- (UIImage*) maskImage:(UIImage *)im 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([im CGImage], mask);
return [UIImage imageWithCGImage:masked];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment