我试图链接两个滤镜(对比度和亮度)并将其应用于图像,但是我只应用了对比滤镜。

这是代码:

UIImage *inputImage = [UIImage imageNamed:@"2.jpg"];
    GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:inputImage];

    //Set Brightness to 60
    GPUImageBrightnessFilter *brightnessFilter = [GPUImageBrightnessFilter new];
    [brightnessFilter setBrightness:0.5];

    //Set Contrast to 12
    GPUImageContrastFilter *contrastFilter = [GPUImageContrastFilter new];
    [contrastFilter setContrast:1.0];

    [contrastFilter addTarget:brightnessFilter];
    [stillImageSource addTarget:contrastFilter];

    [contrastFilter useNextFrameForImageCapture];
    [stillImageSource processImage];

    UIImage *outputImage1 = [contrastFilter imageFromCurrentFramebuffer];
    imageView.image = outputImage1;

最佳答案

我希望这可以解决您的问题。

GPUImageView *imageView = [[GPUImageView alloc] initWithFrame:CGRectMake(x, y, width, height)];
[self.view addSubview:imageView];

UIImage *inputImage = [UIImage imageNamed:@"2.jpg"];
GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:inputImage];

//Set Brightness to 60
GPUImageBrightnessFilter *brightnessFilter = [[GPUImageBrightnessFilter alloc]init];
[brightnessFilter setBrightness:0.5];

//Set Contrast to 12
GPUImageContrastFilter *contrastFilter = [[GPUImageContrastFilter alloc]init];
[contrastFilter setContrast:1.0];

[stillImageSource addTarget:brightnessFilter];
[brightnessFilter addTarget:contrastFilter];
[contrastFilter addTarget:imageView];
[stillImageSource processImage];

[contrastFilter useNextFrameForImageCapture];
UIImage *outputImage1 = [contrastFilter imageFromCurrentFramebuffer];
imageView.image = outputImage1;

关于ios - 链接GPUImage滤镜仅应用最后一个滤镜,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29900707/

10-13 08:39