4

I would like to apply blur on my image view. I have this code for blurring:

- (UIImage *)applyBlurOnImage: (UIImage *)imageToBlur withRadius: (CGFloat)blurRadius
{
    CIImage *originalImage = [CIImage imageWithCGImage: imageToBlur.CGImage];
    CIFilter *filter = [CIFilter filterWithName: @"CIGaussianBlur" keysAndValues: kCIInputImageKey, originalImage, @"inputRadius", @(blurRadius), nil];
    CIImage *outputImage = filter.outputImage; CIContext *context = [CIContext contextWithOptions:nil];
    CGImageRef outImage = [context createCGImage: outputImage fromRect: [outputImage extent]];
    return [UIImage imageWithCGImage: outImage];
}

But blurring happens very slow for screenshot of my UIView on iPad.

Is there any faster way to do this?

Michal
  • 15,429
  • 10
  • 73
  • 104
AYMADA
  • 889
  • 3
  • 17
  • 37

2 Answers2

7

Apple released code at WWDC that does what you need.

It is a category on UIImage and uses the Accelerate framework for fast image processing. If you have a developer account you can grab the UIImage category here.

Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143
  • Did they really release it at WWDC? I remember it wasn't really there for quite some time after the presentation (I think the blur was only on the UIToolbar or whatnot..). But hey, that's awesome! – Michal Apr 08 '14 at 11:51
1

Try this library. It is fairly new and quite fast. Remember that blur is either way quite nasty thing for the device to process, so it won't be zen-like, but it's very good.

OR - you can refer to this question that has some high quality answers.

Community
  • 1
  • 1
Michal
  • 15,429
  • 10
  • 73
  • 104