GPUImage+触摸模糊效果



我需要在我的应用程序中实现触摸模糊效果。我使用GPUImage进行基本过滤,但我也需要包括模糊图像中任何区域的能力。我已经为此挣扎了几天,找不到任何其他有帮助的问题/答案。

我目前的(伪代码)实现没有利用GPUImage,如下所示:

In the pan gesture recognizer, I'm collecting the pan gesture objects and saving them to an array.  When UIGestureRecognizerStateEnded, I attempt to apply the blur using:
1. Get image from GPUImagePicture.
2. Create a "CIGaussianBlur" CIFilter to create a blurred image.
3. Loop through the gesture taps
4. Create a CIFilter mask with a CIRadialGradient with the location as center.
5. Composite the masks into 1 mask: 
maskImage = [[CIFilter filterWithName:@"CISourceOverCompositing" keysAndValues:
             kCIInputImageKey, gassBlur, kCIInputBackgroundImageKey, maskImage, nil] valueForKey:kCIOutputImageKey];
6. Crop the mask:
CIVector *rect = [CIVector vectorWithCGRect:origImage.extent];
maskImage = [CIFilter filterWithName:@"CICrop" keysAndValues:kCIInputImageKey, maskImage, @"inputRectangle", rect, nil].outputImage;
7. Use a CIBlendWithMask filter to combine the original image, the mask, and the blurred image:
CIFilter *blendedFilter = [CIFilter filterWithName:@"CIBlendWithMask" keysAndValues:
                           @"inputImage", pixellateFilter.outputImage,
                           @"inputBackgroundImage", origImage,
                           @"inputMaskImage", maskImage,
                           nil];
8. Update the image view with the new image:
[self.tempImgView setImage:[UIImage imageWithCIImage:pixellateFilter.outputImage]];

如何使模糊效果实时,就像用户在用模糊刷"绘制"图像一样?一个完美的例子就是应用程序Touch Blur。

编辑1:

我的过滤链是这样的:

[self.staticPicture addTarget:self.filter]; // self.filter is some B&W, sepia, etc filter
[self.filter addTarget:self.blurFilter];    // I think the blur filter should be modified somehow
[self.blurFilter addTarget:self.gpuImageView];
[self.staticPicture processImage];

我需要以某种方式更新平移手势事件中的self.bluFilter,然后每次调用processImage来更新gpuImageView。

我最终在我的应用程序You Doodle中使用了一个完全由CPU完成的框模糊。假设你有图像的原始像素,你可以模糊必要的像素,然后执行drawRect,然后将模糊的矩形绘制成UIView。在拥有400万像素图像的iPhone 4S上,模糊速度甚至相当快,在iPad2及更新版本上运行起来像黄油一样光滑。

长方体模糊库:https://github.com/gdawg/uiimage-dsp

最新更新