Last active
December 17, 2015 05:39
-
-
Save joelrfcosta/5559389 to your computer and use it in GitHub Desktop.
Apply blur to UIView
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
//Get a UIImage from the UIView | |
UIGraphicsBeginImageContext(myView.bounds.size); | |
[myView.layer renderInContext:UIGraphicsGetCurrentContext()]; | |
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
//Blur the UIImage | |
CIImage *imageToBlur = [CIImage imageWithCGImage:viewImage.CGImage]; | |
CIFilter *gaussianBlurFilter = [CIFilter filterWithName: @"CIGaussianBlur"]; | |
[gaussianBlurFilter setValue:imageToBlur forKey: @"inputImage"]; | |
[gaussianBlurFilter setValue:[NSNumber numberWithFloat: 10] forKey: @"inputRadius"]; | |
CIImage *resultImage = [gaussianBlurFilter valueForKey: @"outputImage"]; | |
UIImage *endImage = [[UIImage alloc] initWithCIImage:resultImage]; | |
//Place the UIImage in a UIImageView | |
UIImageView *newView = [[UIImageView alloc] initWithFrame:self.view.bounds]; | |
newView.image = endImage; | |
[self.view addSubview:newView]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment