Hello Reader's
If you want to blur image in objective c and swift then copy this code in your project and just call this function. In this code , Blur effect is 50 percent .
For Objective C :-
-(UIImage *)convertToBlurImage:(UIImage *)image{
CIFilter *gaussianBlurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
[gaussianBlurFilter setDefaults];
CIImage *inputImage = [CIImage imageWithCGImage:[image CGImage]];
[gaussianBlurFilter setValue:inputImage forKey:kCIInputImageKey];
[gaussianBlurFilter setValue:@50 forKey:kCIInputRadiusKey];
CIImage *outputImage = [gaussianBlurFilter outputImage];
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef cgimg = [context createCGImage:outputImage fromRect:[inputImage extent]]; // note, use input image extent if you want it the same size, the output image extent is larger
UIImage *convertedImage = [UIImage imageWithCGImage:cgimg];
return convertedImage;
}
For Swift :-
func convertToBlurImage(image:UIImage)->(UIImage){
var imageToBlur = CIImage(image: image)
var blurfilter = CIFilter(name: "CIGaussianBlur")
blurfilter.setValue("5", forKey:kCIInputRadiusKey)
blurfilter.setValue(imageToBlur, forKey: "inputImage")
var resultImage = blurfilter.valueForKey("outputImage") as CIImage
var blurredImage = UIImage(CIImage: resultImage)
return blurredImage!
}
0 Comment(s)