gran33
gran33

Reputation: 12951

iOS - blur effect - GPUImage - processImageWithCompletionHandler

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?

Upvotes: 3

Views: 461

Answers (2)

gabuh
gabuh

Reputation: 1166

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.

Upvotes: 1

Related Questions