iOS - 模糊效果 - GPUImage - processImageWithCompletionHandler

时间:2014-05-28 08:24:48

标签: ios gpuimage

我使用GPUImage进行模糊效果,并使我的侧面菜单背景模糊(它的POC代码):

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 - 实际处理和模糊屏幕截图的方法需要1秒钟(这很多!)。

如何让它更快或有人有不同于截图的技巧?

提前10倍!

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

我建议您使用UIImage + ImageEffects类别。您可以从WWDC 2013示例代码(需要付费开发人员订阅)获取它并下载iOS_UIImageEffects,然后您可以获取UIImage + ImageEffects类别。或者从

下载

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

它为您提供:

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

所以要做一个模糊你只需做:

UIImage *newImage = [image applyLightEffect];

这很快。看看吧。