我需要将高斯模糊应用于NSImage
由于此图像在应用程序的生命周期中发生了很大变化,因此操作应该很快,以便UI保持一定的响应性。
不幸的是,我还没有找到解决这个问题的令人满意的解决方案。
基本上,我尝试了三件事:
将高斯模糊(或任何过滤器)应用于NSImage
的最快方法是什么?
CIImage *imageToBlur = [CIImage imageWithData:[backgroundImage TIFFRepresentation]];
CIFilter *gaussianBlurFilter = [CIFilter filterWithName: @"CIGaussianBlur"];
[gaussianBlurFilter setValue:imageToBlur forKey:kCIInputImageKey];
[gaussianBlurFilter setValue:[NSNumber numberWithFloat: 10] forKey: @"inputRadius"];
NSCIImageRep *rep = [NSCIImageRep imageRepWithCIImage:[gaussianBlurFilter valueForKey:kCIOutputImageKey]];
NSImage *nsImage = [[NSImage alloc] initWithSize:rep.size];
[nsImage addRepresentation:rep];
_backgroundImage = nsImage;
GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:backgroundImage];
GPUImageGaussianBlurFilter *gaussianBlurFilter = [[GPUImageGaussianBlurFilter alloc] init];
gaussianBlurFilter.blurRadiusInPixels = 10.0;
[stillImageSource addTarget:gaussianBlurFilter];
[stillImageSource processImage];
_backgroundImage = [gaussianBlurFilter imageFromCurrentlyProcessedOutput];