Created
July 12, 2013 23:27
-
-
Save betzerra/5988604 to your computer and use it in GitHub Desktop.
Blurred image using CoreImage (iOS 6)
This file contains hidden or 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
// Needs CoreImage.framework | |
- (UIImage *)blurredImageWithImage:(UIImage *)sourceImage{ | |
// Create our blurred image | |
CIContext *context = [CIContext contextWithOptions:nil]; | |
CIImage *inputImage = [CIImage imageWithCGImage:sourceImage.CGImage]; | |
// Setting up Gaussian Blur | |
CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"]; | |
[filter setValue:inputImage forKey:kCIInputImageKey]; | |
[filter setValue:[NSNumber numberWithFloat:15.0f] forKey:@"inputRadius"]; | |
CIImage *result = [filter valueForKey:kCIOutputImageKey]; | |
/* CIGaussianBlur has a tendency to shrink the image a little, this ensures it matches | |
* up exactly to the bounds of our original image */ | |
CGImageRef cgImage = [context createCGImage:result fromRect:[inputImage extent]]; | |
UIImage *retVal = [UIImage imageWithCGImage:cgImage]; | |
return retVal; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! I had no idea a gist was a code snippet. These are useful!