我需要在我的应用中实现触摸模糊效果。我正在使用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];
我需要以某种方式更新pan手势事件中的self.blurFilter,然后每次调用processImage来更新gpuImageView。
答案 0 :(得分:2)
我最终在我的应用程序中使用了一个框模糊,You Doodle完全在CPU上完成。假设您拥有图像的原始像素,则可以模糊必要的像素,然后执行drawRect,然后将模糊的矩形绘制为UIView。在具有400万像素图像的iPhone 4S上,模糊效果甚至可以非常快,并且在iPad 2和更新版本上运行时非常流畅。
Box blur library:https://github.com/gdawg/uiimage-dsp