Skip to content

Instantly share code, notes, and snippets.

@jsai
Last active December 26, 2015 13:29
Embed
What would you like to do?
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