Skip to content

Instantly share code, notes, and snippets.

@ZachOrr
Forked from betzerra/gist:5988604
Created May 28, 2015 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZachOrr/7c338f899dc40d29db8a to your computer and use it in GitHub Desktop.
Save ZachOrr/7c338f899dc40d29db8a to your computer and use it in GitHub Desktop.
// 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];
CGImageRelease(cgImage);
return retVal;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment