ran*_*dom 21 image core-graphics image-processing objective-c uiimageview
我在尝试模糊iOS应用中的部分屏幕时遇到了麻烦.请参阅图片以更好地了解我正在尝试做什么.

只有"BlurBox"的内容需要模糊,但其余内容可以清晰.因此,如果您正在查看表格视图,则只有BlurBox下方的内容会模糊(即使您滚动).其余的看起来很清楚.
我的第一个方法是调用UIGraphicsGetImageFromCurrentImageContext()每个.01s来将BlurBox下的所有图层组合成一个图像.然后模糊该图像并将其显示在所有内容上.
我尝试模糊的方法是:
https://github.com/tomsoft1/StackBluriOS
https://github.com/coryleach/UIImageAdjust
https://github.com/esilverberg/ios-image-filters
https://github.com/cmkilger/CKImageAdditions
[layer setRasterizationScale:0.25];
[layer setShouldRasterize:YES];
以及一些自定义尝试.我也看过Apple的GLImageProcessing,但我认为对于我在这里尝试做的事情来说有点矫枉过正.
问题是,他们都是以 减缓.该应用程序不在应用程序商店上,所以我愿意使用任何私有/未记录的框架.
我有一种很远的想法是覆盖drawRect我使用的所有组件(UITableViewCells,UITableView等)的方法,并在运行中独立模糊它们.然而,这需要一些时间,这听起来像是一个可行的选择吗?
更新:
我尝试使用CIFilters如下:
CIImage *inputImage = [[CIImage alloc] initWithImage:[self screenshot]];
CIFilter *blurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
[blurFilter setDefaults];
[blurFilter setValue: inputImage forKey: @"inputImage"];
[blurFilter setValue: [NSNumber numberWithFloat:10.0f]
                           forKey:@"inputRadius"];
CIImage *outputImage = [blurFilter valueForKey: @"outputImage"];
CIContext *context = [CIContext contextWithOptions:nil];
self.bluredImageView.image = [UIImage imageWithCGImage:[context createCGImage:outputImage fromRect:outputImage.extent]];
这确实有效,但速度非常慢.:(
我发现只有当我传入从磁盘加载的图像时,某些实现才会模糊.如果我传入我使用UIGraphicsGetImageFromCurrentImageContext()它创建的UIImage 不起作用.关于为什么会这样的任何想法?
更新:
我试过如下的Patel建议:
CALayer *backgroundLayer = [CALayer layer];
CIFilter *blurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
[blurFilter setDefaults];
backgroundLayer.backgroundFilters = [NSArray arrayWithObject:blurFilter];
[[self.view layer] addSublayer:backgroundLayer];
但是,它不起作用:(
更新后的更新:
我已经设法使用TomSoft1的stackblur使BlurBox正常工作,因为他添加了将图像标准化为RGBA格式(32位/像素)的功能.但是,它仍然很慢.
我有一个计时器每0.03秒调用一次更新,以获取BlurBox下面的图像,模糊该图像,并在屏幕上显示.我需要帮助提高BlurBox上的"fps".
bry*_*yle 41
我会推荐Brad Larson的GPUImage,它完全由GPU支持,可用于各种图像处理效果.它非常快,甚至足够快,在他的演示应用程序中,他从相机进行实时视频处理,帧速率非常好.
https://github.com/BradLarson/GPUImage
这是我编写的代码片段,用于应用基本的盒子模糊,模糊图像的底部和顶部三分之一,但使图像的中间不模糊.他的图书馆非常广泛,几乎包含了各种可想象的图像滤镜效果.
GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:[self screenshot]];
GPUImageTiltShiftFilter *boxBlur = [[GPUImageTiltShiftFilter alloc] init];
        boxBlur.blurSize = 0.5;
[stillImageSource addTarget:boxBlur];
[stillImageSource processImage];
UIImage *processedImage = [stillImageSource imageFromCurrentlyProcessedOutput];
小智 7
虽然回复可能有点迟,但您可以使用Core Image过滤器.这条线很慢的原因.
CIContext *context = [CIContext contextWithOptions:nil];
在Apple文档中,为了在Core Image中获得最佳性能,他们首先说明了这一点
" CIContext每次渲染时都不要创建对象.上下文存储了大量的状态信息;重用它们的效率更高."
我个人的解决方案是为Core Image Context创建一个Singleton.所以我只创造一个.
我的代码在GitHub上的这个演示项目中.
https://github.com/KyleLopez/DemoCoreImage
随意使用它,或根据自己的喜好找到其他解决方案.我在CoreImage中找到的最慢的部分是上下文,之后的图像处理非常快.
| 归档时间: | 
 | 
| 查看次数: | 35167 次 | 
| 最近记录: |