Skip to content

Instantly share code, notes, and snippets.

@betzerra
Created July 12, 2013 23:27
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save betzerra/5988604 to your computer and use it in GitHub Desktop.
Save betzerra/5988604 to your computer and use it in GitHub Desktop.
Blurred image using CoreImage (iOS 6)
// 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;
}
@MattA9K
Copy link

MattA9K commented Mar 25, 2021

Nice! I had no idea a gist was a code snippet. These are useful!

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