简体   繁体   English

在iOS上非常慢的UIImage模糊

[英]Very slow UIImage blurring on iOS

I would like to apply blur on my image view. 我想在我的图像视图上应用模糊。 I have this code for blurring: 我有这个代码模糊:

- (UIImage *)applyBlurOnImage: (UIImage *)imageToBlur withRadius: (CGFloat)blurRadius
{
    CIImage *originalImage = [CIImage imageWithCGImage: imageToBlur.CGImage];
    CIFilter *filter = [CIFilter filterWithName: @"CIGaussianBlur" keysAndValues: kCIInputImageKey, originalImage, @"inputRadius", @(blurRadius), nil];
    CIImage *outputImage = filter.outputImage; CIContext *context = [CIContext contextWithOptions:nil];
    CGImageRef outImage = [context createCGImage: outputImage fromRect: [outputImage extent]];
    return [UIImage imageWithCGImage: outImage];
}

But blurring happens very slow for screenshot of my UIView on iPad. 但是对于我的UIView在iPad上的截图,模糊发生的速度非常慢。

Is there any faster way to do this? 有没有更快的方法来做到这一点?

Apple released code at WWDC that does what you need. Apple在WWDC上发布了满足您需求的代码。

It is a category on UIImage and uses the Accelerate framework for fast image processing. 它是UIImage上的一个类别,使用Accelerate框架进行快速图像处理。 If you have a developer account you can grab the UIImage category here . 如果您有开发者帐户,可以在此处获取UIImage类别。

Try this library. 试试这个库。 It is fairly new and quite fast. 它相当新,速度很快。 Remember that blur is either way quite nasty thing for the device to process, so it won't be zen-like, but it's very good. 请记住,模糊对于设备来说要么是非常讨厌的事情,所以它不会像禅一样,但它非常好。

OR - you can refer to this question that has some high quality answers. 或者 - 你可以参考这个有一些高质量答案的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM