Skip to content

Instantly share code, notes, and snippets.

@jsai
Last active December 26, 2015 13:29
Show Gist options
  • Save jsai/7159010 to your computer and use it in GitHub Desktop.
Save jsai/7159010 to your computer and use it in GitHub Desktop.
UIImage Blur
- (UIImage *)blurredImageWithRadius:(CGFloat)radius {
CIImage *inputImage = [[CIImage alloc] initWithCGImage:self.CGImage];
CIFilter *blurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
[blurFilter setDefaults];
[blurFilter setValue:inputImage forKey:kCIInputImageKey];
[blurFilter setValue:@(radius) forKey:@"inputRadius"];
CIImage *outputImage = [blurFilter valueForKey:kCIOutputImageKey];
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef imageConvertedToCG = [context createCGImage:outputImage
fromRect:inputImage.extent];
UIImage *blurredImage = [UIImage imageWithCGImage:imageConvertedToCG
scale:self.scale
orientation:self.imageOrientation];
CGImageRelease(imageConvertedToCG);
return blurredImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment