I have a project with several kernel image filters, each of which is associated with a different slider. Everything works, but I just did not understand the best way to transfer the results from one filter to another. Each time, each reset changes any of the other sliders. The reason is that the original image created from the imported image fits into each filter as the input image. But you don’t know how to fix it.
I am trying to imagine a better way to pass the results of multiple filters into a single output image.
here is the project: owolf.net/uploads/StackOverflow/CoreImageFilter.zip
and some of the viewControler code inserted below:
- (void)viewDidLoad
{
UIImage *aUIImage = [imageView image];
CGImageRef aCGImage = aUIImage.CGImage;
aCIImage = [CIImage imageWithCGImage:aCGImage];
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];
}