我有一个项目有几个核心图像过滤器,每个都连接到不同的滑块。一切正常,但我还没有想出将结果从一个过滤器传递到下一个过滤器的最佳方法。每次我更改任何其他滑块时,它们都会重置。原因是从导入图像创建的原始图像被每个过滤器绘制为输入图像。但不知道如何解决这个问题。
我正在尝试考虑将多个过滤器的结果传递到一个输出图像的最佳方法。
这是项目: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];
}