GPUImageGaussianSelectiveBlurFilter选择区域问题

时间:2014-02-12 13:29:23

标签: ios objective-c cocoa-touch ios7 gpuimage

我使用过GPUImageGaussianSelectiveBlurFilter

    imagePic = [[GPUImagePicture alloc] initWithImage:captureImage];// given a input in gpuimagepicture for process a image
filter = [[GPUImageGaussianSelectiveBlurFilter alloc] init];
[imagePic addTarget:filter];// add a filter for image

// create  a view for set a image in that view
imageViewGpu=[[GPUImageView alloc] initWithFrame:CGRectMake((self.view.frame.size.width-OutputImageView.frame.size.width)/2.0, (biManager.displayImageHeight-OutputImageView.frame.size.height)/2.0, OutputImageView.frame.size.width, OutputImageView.frame.size.height)];
imageViewGpu.userInteractionEnabled = YES;

imageViewGpu.frame=OutputImageView.frame;
imageViewGpu.multipleTouchEnabled= YES;
imageViewGpu.backgroundColor = [UIColor clearColor];
imageViewGpu.userInteractionEnabled = YES;
imageViewGpu.fillMode=kGPUImageFillModePreserveAspectRatio;
[self.view addSubview:imageViewGpu];
[(GPUImageGaussianSelectiveBlurFilter *) filter setExcludeCircleRadius:0.3f];

[(GPUImageGaussianSelectiveBlurFilter *) filter setExcludeCirclePoint:CGPointMake(0,0)];
[filter addTarget:imageViewGpu];
[filter prepareForImageCapture];
[imagePic processImage];// get a filter apply image

我的输出是

enter image description here

但我需要这个输出

enter image description here

我认为这个过滤器非常适合使用方形图像。但它没有正确使用Rectangle图像。请帮助我。

3 个答案:

答案 0 :(得分:1)

将过滤器的aspectRatio属性设置为图像的宽高比。

filter.aspectRatio = imagePix.size.width/imagePix.size.height

如果这不起作用交换宽度/高度:]

答案 1 :(得分:0)

将图像绘制成更高但宽度相同的方形缓冲区。模糊它。将其复制回较小的矩形缓冲区。

答案 2 :(得分:0)

    if (imageViewGpu.frame.size.height>imageViewGpu.frame.size.width) {

        [(GPUImageGaussianSelectiveBlurFilter *) filter setAspectRatio:imageViewGpu.frame.size.height/imageViewGpu.frame.size.width];
}
else
{

    [(GPUImageGaussianSelectiveBlurFilter *) filter setAspectRatio:imageViewGpu.frame.size.width/imageViewGpu.frame.size.height];

}

以上代码运作良好