Last active
December 26, 2015 13:29
-
-
Save jsai/7159010 to your computer and use it in GitHub Desktop.
UIImage Blur
This file contains 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
- (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