2013-07-23 112 views
2

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

回答

2

我最终在我的应用程序中使用了框模糊,You Doodle完全在CPU上完成。假设您的图像具有原始像素,则可以模糊所需的像素,然后执行drawRect,然后将模糊的矩形绘制到UIView。在具有4百万像素图像的iPhone 4S上,模糊效果甚至非常快,并且在iPad 2和更新的版本上运行流畅。

框模糊库:https://github.com/gdawg/uiimage-dsp