Last active
January 5, 2018 10:57
-
-
Save anaglik/6055542 to your computer and use it in GitHub Desktop.
Example of "CIMaskToAlpha" filter's usage.
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
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]; |
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
Thank You! Is a SuperGood Example 😄