2013-07-23 110 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