Skip to content

Instantly share code, notes, and snippets.

@anaglik
Last active January 5, 2018 10:57
Show Gist options
  • Save anaglik/6055542 to your computer and use it in GitHub Desktop.
Save anaglik/6055542 to your computer and use it in GitHub Desktop.
Example of "CIMaskToAlpha" filter's usage.
CIContext *context = [CIContext contextWithOptions:nil];
UIImage *entryImage = [UIImage imageNamed:@"someImage.png"];
CIImage *image = [CIImage imageWithCGImage:[entryImage CGImage]];
CIFilter *filter = [CIFilter filterWithName:@"CIMaskToAlpha"];
[filter setValue:image forKey:kCIInputImageKey];
CIImage *result = [filter valueForKey:kCIOutputImageKey];
CGImageRef cgImage = [context createCGImage:result fromRect:[result extent]];
UIImage *newImage = [UIImage imageWithCGImage:cgImage scale:[entryImage scale] orientation:UIImageOrientationUp];
@raulsilvamx
Copy link

Thank You! Is a SuperGood Example 😄

@lukas2
Copy link

lukas2 commented Jan 5, 2018

Thank you, that was useful.
Here's a version in Swift using a slightly shorter syntax: https://gist.github.com/lukas2/9723e3b125e5eaf856848c5c015adca5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment