2015-03-02 83 views
0

我已經使用StackBlur進行圖像模糊,但對於大分辨率的照片來說太慢了......所以我決定隨着每個人都說它是最好的使用方法而開關GPUImage library使用GPUImage庫的高斯模糊

我用只是這一行代碼使用StackBlur實現模糊:

_editedImage = [_myImage stackBlur:round(self.blurSlider.value)]; 

但我無法弄清楚如何以同樣的方式使用GPUImage ...

有在網上很多例子,但他們都是過時的,因爲GPUImage更新..

有人可以請幫我實現高斯模糊?

對不起,如果這聽起來很愚蠢......我是新的objective-c。

回答

1

你會想要做這樣的事情(雖然未經測試,因此可能無法正常工作的第一次;)

- (UIImage*)blurImage { 
    GPUImagePicture *source = [[GPUImagePicture alloc] initWithImage:self]; 
    GPUImageiOSBlurFilter *blur = [[GPUImageiOSBlurFilter alloc] init]; 
    blur.blurRadiusInPixels = 1.0f; 
    [source addTarget:blur]; 
    [blur processImage]; 
    return [blur imageFromCurrentFramebuffer]; 
} 
+0

謝謝你,但Xcode中給出了錯誤:'[過濾imageFromCurrentFramebuffer]' - 宣言「過濾器」必須從模塊「Darwin.ncurses」之前進口是必須的; &壞接收器類型'void(*)(void)'; – Edgar 2015-03-03 12:55:47

+0

哎呦。更改過濾器來源;) – brandonscript 2015-03-03 15:51:39

+0

更新了示例,我認爲它現在是正確的。我總是對過濾器鏈接的方式感到困惑。 – brandonscript 2015-03-03 16:56:54

1

這一個是GPUImageGaussianSelectiveBlurFilter。

我希望它可以幫助你..

GPUImageGaussianSelectiveBlurFilter *selectiveBlur; 
GPUImagePicture *fx_image; 
UIImage *final_image; 

-(IBAction)upDateSliderValue:(id)sender 
{  
fx_image = [[GPUImagePicture alloc] initWithImage:originalImage]; 
[self aspectRatio]; //to get the Value of f.. 
[selectiveBlur setAspectRatio:f]; 
[selectiveBlur setExcludeCircleRadius:self.sliderChange.value]; 
[fx_image addTarget:selectiveBlur]; 
[fx_image processImage]; 
final_image = [selectiveBlur imageFromCurrentlyProcessedOutput]; 
selectedImageView.image = final_image; 
}