Created
April 30, 2015 09:36
-
-
Save Air-Craft/e9acc32dc27d6681394f to your computer and use it in GitHub Desktop.
Apply CIFilter to a CALayer #CoreImage #image-manipulation #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
// SIMPLE | |
// Note: Can convert to UIImage but there's no way to go to CGImage. | |
CIImage *newImg = [[CIImage imageWithCGImage:img.CGImage] imageByApplyingFilter:@"CIColorMonochrome" | |
withInputParameters:@{kCIInputColorKey: ciCol}]; | |
// EXTENDED | |
CIContext *ctx = [CIContext contextWithOptions:nil]; | |
CIFilter *filter = [CIFilter filterWithName:@"CIColorMonochrome"]; | |
CIColor *color = [CIColor colorWithRed:pitchTilt green:rollTilt blue:1.0 alpha:1.0]; | |
[filter setDefaults]; | |
[filter setValue:[CIImage imageWithCGImage:img.CGImage] forKey:kCIInputImageKey]; | |
[filter setValue:color forKey:kCIInputColorKey]; | |
CGImageRef cgImg = [ctx createCGImage:filter.outputImage fromRect:filter.outputImage.extent]; | |
static CALayer *l; | |
if (!l) { | |
l = [CALayer layer]; | |
l.frame = CGRectMake(0, 0, filter.outputImage.extent.size.width/2.0, filter.outputImage.extent.size.height/2.0); | |
[_instrumentPanel.layer addSublayer:l]; | |
l.contentsScale = 2.0; | |
} | |
l.contents = (__bridge id)(cgImg); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment