我需要在我的应用程序中实现触摸模糊效果。我使用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.blurFilter,然后每次调用 processImage 来更新 gpuImageView。