gpt4 book ai didi

ios - 如何使用多个核心图像过滤器影响图像(不重置结果)

转载 作者:可可西里 更新时间:2023-11-01 04:19:12 24 4
gpt4 key购买 nike

我有一个包含多个核心图像过滤器的项目,每个过滤器都连接到不同的 slider 。一切正常,但我还没有找到将结果从一个过滤器传递到下一个过滤器的最佳方法。每次我更改任何其他 slider 时,它们都会重置。原因是因为从导入图像创建的原始图像被每个过滤器作为输入图像绘制。但不确定如何解决这个问题。

我正在尝试考虑将多个过滤器的结果传递到一个输出图像中的最佳方法。

这是项目:owolf.net/uploads/StackOverflow/CoreImageFilter.zip

下面粘贴了一些 viewControler 的代码:

- (void)viewDidLoad
{
//Create CIImage
UIImage *aUIImage = [imageView image];
CGImageRef aCGImage = aUIImage.CGImage;
aCIImage = [CIImage imageWithCGImage:aCGImage];

//Create context
context = [CIContext contextWithOptions:nil];

saturationFilter = [CIFilter filterWithName:@"CIColorControls" keysAndValues: @"inputImage", aCIImage, nil];
brightnessFilter = [CIFilter filterWithName:@"CIColorControls" keysAndValues: @"inputImage", aCIImage, nil];
contrastFilter = [CIFilter filterWithName:@"CIColorControls" keysAndValues: @"inputImage", aCIImage, nil];
[super viewDidLoad];
}


- (IBAction)saturationSliderValueChanged:(id)sender {
outputImage = [saturationFilter outputImage];
CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]];
newUIImage = [UIImage imageWithCGImage:cgimg];
CGImageRelease(cgimg);
[imageView setImage:newUIImage];
}

- (IBAction)brightnessSliderValueChanged:(id)sender {
[brightnessFilter setValue:[NSNumber numberWithFloat:brigtnessSlider.value] forKey: @"inputBrightness"];
outputImage = [brightnessFilter outputImage];
CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]];
newUIImage = [UIImage imageWithCGImage:cgimg];
CGImageRelease(cgimg);
[imageView setImage:newUIImage];
}

- (IBAction)contrastSliderValueChanged:(id)sender {
[contrastFilter setValue:[NSNumber numberWithFloat:contrastSlider.value] forKey: @"inputContrast"];
outputImage = [contrastFilter outputImage];
CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]];
newUIImage = [UIImage imageWithCGImage:cgimg];
CGImageRelease(cgimg);
[imageView setImage:newUIImage];
}

最佳答案

您需要选择应用滤镜的顺序,然后将第一个滤镜的输出用作第二个滤镜的输入图像,依此类推。这是我的一个项目中的示例:

CIImage *adjustedImage = self.originalImage;

[self.vibranceFilter setValue:adjustedImage forKey:@"inputImage"];
adjustedImage = [self.vibranceFilter outputImage];

[self.hueFilter setValue:adjustedImage forKey:@"inputImage"];
adjustedImage = [self.hueFilter outputImage];

[self.vignetteFilter setValue:adjustedImage forKey:@"inputImage"];
adjustedImage = [self.vignetteFilter outputImage];

CGImageRef cgImage = [self.imageContext createCGImage:adjustedImage fromRect:[adjustedImage extent]];

self.imageView.image = [UIImage imageWithCGImage:cgImage];

CGImageRelease(cgImage);

adjustedImage 有效地累积了 Core Image 过滤器的效果。这一切都在它自己的方法中进行,只要您的任何 slider 值发生变化,就会调用该方法。

关于ios - 如何使用多个核心图像过滤器影响图像(不重置结果),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11928279/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com