iOS - 模糊效果 - GPUImage - processImageWithCompletionHandler

3
我正在使用 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秒钟的时间(这是相当长的时间!)。

我该如何让它更快一些?或者有没有其他方法可以代替屏幕截图?


请看这个也许这可以解决你的问题 - Viper
根据我对这个操作的基准测试,那听起来一点也不对:http://www.sunsetlakesoftware.com/2013/10/21/optimizing-gaussian-blurs-mobile-gpu。你是不是在模拟器上运行?模拟器软件模拟OpenGL ES着色器,有时比实际设备慢得多。即使是iPhone 4也应该能在少于150毫秒的时间内运行屏幕分辨率图像。此外,这个时间是否包括屏幕截图UIImage捕获和GPUImagePicture创建?我知道这些部分会很慢,因为通过Core Graphics旅行是一个限制。 - Brad Larson
2个回答

1
我建议您使用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];

它非常快。检查一下。



网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接