【问题标题】:Multiple Filters using GPUImage Library使用 GPUImage 库的多个过滤器
【发布时间】:2013-09-08 20:02:36
【问题描述】:

我正在尝试对图像应用 3 个滤镜。

一个 rgbFilter 的值是恒定的,一个亮度过滤器和一个饱和度过滤器,它们都应该能够被修改并且图像应该更新。

我已经听从了here的建议。

我已经使用 IB 设置了一个 UIView,并将其类设置为 GPUImageView。由于某种原因,图像没有显示。

我的步骤如下:

self.gpuImagePicture = [[GPUImagePicture alloc] initWithImage:image];
[self.gpuImagePicture addTarget:self.brightnessFilter];
[self.brightnessFilter addTarget:self.contrastFilter];
[self.contrastFilter addTarget:self.imageView];

然后我称它为在 rgb 过滤器上设置常量值

[self setRGBFilterValues]

我在此之前设置了我的过滤器:

- (void) setupFilters
{
    self.brightnessFilter = [[GPUImageBrightnessFilter alloc] init];
    self.contrastFilter = [[GPUImageContrastFilter alloc] init];
    self.rgbFilter = [[GPUImageRGBFilter alloc] init];
}

我错过了一个步骤还是为什么图像什么都不显示?

【问题讨论】:

    标签: ios gpuimage


    【解决方案1】:

    你少了一步。您需要在您的 GPUImagePicture 实例上调用 -processImage 以使其通过过滤器链传播。

    您还需要在更改过滤器链中的值并希望更新最终输出时调用它。

    【讨论】:

    • @Brad Larson 但是,这个-processImage 只能调用一次?还是每次将滤镜应用于图像?
    • @MinSoe - 每当您需要通过过滤器链传播图像时,例如过滤器或过滤器设置已更改时。
    【解决方案2】:

    这是我第一次使用这个 GPUImage 库,我花了很长时间才弄清楚如何简单地将多个滤镜应用于单个图像。 OP 提供的link 确实有助于解释为什么 API 相对复杂(原因之一:您必须指定应用过滤器的顺序)。

    为了将来参考,这是我应用两个过滤器的代码:

    UIImage *initialImage = ...
    GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:initialImage];
    
    GPUImageSaturationFilter *saturationFilter = [[GPUImageSaturationFilter alloc] init];
    saturationFilter.saturation = 0.5;
    [stillImageSource addTarget:saturationFilter];
    
    GPUImageGaussianBlurFilter *blurFilter = [[GPUImageGaussianBlurFilter alloc] init];
    blurFilter.blurRadiusInPixels = 10;
    [saturationFilter addTarget:blurFilter];
    
    GPUImageFilter *lastFilter = blurFilter;
    [lastFilter useNextFrameForImageCapture];
    [stillImageSource processImage];
    UIImage *processedImage = [lastFilter imageFromCurrentFramebuffer];
    

    【讨论】:

    • 现在在 Swift 中使用 CIImageFilters 和函数技术更容易了。查看 Objc.io 函数式编程速成书。 objc.io/books/fpinswift
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-05
    • 1970-01-01
    相关资源
    最近更新 更多