I want to blur an UIImage for an app, Does any of you have an Objective-C method to blur an image ?
I tried to find a method or a technique but couldn't find anything. Help please !
I want to blur an UIImage for an app, Does any of you have an Objective-C method to blur an image ?
I tried to find a method or a technique but couldn't find anything. Help please !
You can use core image filters. http://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html
Look at this snippet from https://gist.github.com/betzerra/5988604
//  Needs CoreImage.framework
- (UIImage *)blurredImageWithImage:(UIImage *)sourceImage{
    //  Create our blurred image
    CIContext *context = [CIContext contextWithOptions:nil];
    CIImage *inputImage = [CIImage imageWithCGImage:sourceImage.CGImage];
    //  Setting up Gaussian Blur
    CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
    [filter setValue:inputImage forKey:kCIInputImageKey];
    [filter setValue:[NSNumber numberWithFloat:15.0f] forKey:@"inputRadius"];
    CIImage *result = [filter valueForKey:kCIOutputImageKey];
    /*  CIGaussianBlur has a tendency to shrink the image a little, this ensures it matches 
     *  up exactly to the bounds of our original image */
    CGImageRef cgImage = [context createCGImage:result fromRect:[inputImage extent]];
    UIImage *retVal = [UIImage imageWithCGImage:cgImage];
    if (cgImage) {
        CGImageRelease(cgImage);
    }
    return retVal;
}
You can use UIVisualEffectView with visual effects. Initialize an element of visualEffect and effectView than add to your view or imgview wherever you want :). Also you can choose EffectStyles. code snippet :
UIVisualEffect *blurEffect;
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView *visualEffectView;
visualEffectView = [[UIVisualEffectView alloc]initWithEffect:blurEffect];
visualEffectView.frame = YourImgView.bounds;
[YourImgView addSubview:visualEffectView];
Solution :
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
    blurEffectView.frame = self.view.bounds;
    blurEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    //ADD BLUR EFFECT VIEW IN MAIN VIEW
    [self.view addSubview:blurEffectView];
I recommend to use Storyboard for implementing blur or vibrancy by UIVisualEffectView. For more, look at my sample project at https://github.com/Vaberer/BlurTransition to demonstrate how to it works and how use it with autolayout inside the UIVisualEffect
Swift 2.2 :
 func blurredImage(with sourceImage: UIImage) -> UIImage {
        let filter = CIFilter(name: "CIGaussianBlur")
        filter!.setValue(CIImage(image: sourceImage), forKey: kCIInputImageKey)
        filter!.setValue(0.8, forKey: kCIInputIntensityKey)
        let ctx = CIContext(options:nil)
        let cgImage = ctx.createCGImage(filter!.outputImage!, fromRect:filter!.outputImage!.extent)
        return UIImage(CGImage:cgImage)
}