3

I'm using GPUImage for blur effect and I make my side menu background blur (it's POC code):

UIImage *currentScreenShotImage = [Util screenshot];

GPUImageView *blurView = [[GPUImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
blurView.clipsToBounds = YES;
blurView.layer.contentsGravity = kCAGravityTop;

GPUImageiOSBlurFilter *blurFilter = [[GPUImageiOSBlurFilter alloc] init];
blurFilter.blurRadiusInPixels = 8.0f;

GPUImagePicture *picture = [[GPUImagePicture alloc] initWithImage:currentScreenShotImage];

[picture addTarget:blurFilter];
[blurFilter addTarget:blurView];

[picture processImageWithCompletionHandler:^{
    [blurFilter removeAllTargets];
}];

processImageWithCompletionHandler - The method that actually process and blur the screenshot takes 1 second (which is a lot!).

How can I make it faster or someone have different trick than screenshot?

VLAZ
  • 26,331
  • 9
  • 49
  • 67
gran33
  • 12,421
  • 9
  • 48
  • 76
  • Take a look at [this][1] [1]: http://stackoverflow.com/questions/17041669/creating-a-blurring-overlay-view May be this solve your purpose – Viper May 28 '14 at 09:03
  • That doesn't sound right at all, based on my benchmarks of this operation: http://www.sunsetlakesoftware.com/2013/10/21/optimizing-gaussian-blurs-mobile-gpu . Are you by chance running this on the Simulator? The Simulator software-emulates OpenGL ES shaders, which makes it far slower than actual devices sometimes. Even an iPhone 4 should be able to run this in less than 150 ms on a screen-resolution image. Also, does the timing for this include the screenshot UIImage capture and GPUImagePicture creation? Those parts I know will be slow, as traveling through Core Graphics is a limit there. – Brad Larson May 28 '14 at 15:37

2 Answers2

1

I recommend you to use the UIImage+ImageEffects category. You could get it from the WWDC 2013 sample code (paid developer subscription required) and download iOS_UIImageEffects, you can then grab the UIImage+ImageEffects category. Or download from

https://github.com/iGriever/TWSReleaseNotesView/blob/master/TWSReleaseNotesView/UIImage+ImageEffects.h

That provides you with:

- (UIImage *)applyLightEffect;
- (UIImage *)applyExtraLightEffect;
- (UIImage *)applyDarkEffect;
- (UIImage *)applyTintEffectWithColor:(UIColor *)tintColor;
- (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage;

So to make a blur you just have to do:

UIImage *newImage = [image applyLightEffect];

It's quite fast. Check it out.

gabuh
  • 1,166
  • 8
  • 15