Reputation: 303
I have a problem with adding multiple CIFilters on image, f.e. when I add brightness filter and then try to add contrast image goes to original (losses brightness filter) and then adds contrast filter.
- (IBAction)brightnessSlider:(NSSlider*)sender {
ViewController *controller = (ViewController*)[NSApplication sharedApplication].keyWindow.contentViewController;
CIFilter *brightness = [CIFilter filterWithName:@"CIColorControls" keysAndValues: kCIInputImageKey, originalCIImage, @"inputBrightness", [NSNumber numberWithFloat:[sender floatValue]], nil];
controller.imageView.image = [self fromCIImageToNSImage:[brightness outputImage]];
}
- (IBAction)contrastSlider:(id)sender {
ViewController *controller = (ViewController*)[NSApplication sharedApplication].keyWindow.contentViewController;
CIFilter *contrast = [CIFilter filterWithName:@"CIColorControls" keysAndValues: kCIInputImageKey, originalCIImage, @"inputContrast", [NSNumber numberWithFloat:[sender floatValue]], nil];
controller.imageView.image = [self fromCIImageToNSImage:[contrast outputImage]];
}
If I use originalCIImage = [CIFilter outputImage];
(CIFilter = brightness/contrast) after adding brightness and contrast (applying filters for changed image), then the image goes completely black/grey/white.
How to prevent image from changing back to original and apply several filters simultaneously?
I have read this post answer link of the post but applying filters to original image just resets the image as it should..
Upvotes: 2
Views: 1443
Reputation: 303
So I came in with a solution for this each time slider is used I applied all the filters in each slider. (Let's say I have brightness and contrast slider).
F.e.: 1) when contrast slider is used I apply brightness and contrast filter on image and save the contrast slider value.
2) when brightness slider is used I apply contrast (with saved value) filter and then brightness filter and save brightness slider value.
3) etc.
Hope someone will get this useful!
Upvotes: 1
Reputation: 131418
Your code is applying one filter to the original image if you click the first button, and applying a different filter to the original image if you click the other button.
If you want to apply 2 filters, you need to write code that takes the original image, feeds it into the input of the first filter, sets the other parameters, then gets the output into another CIImage.
Then you need to feed the output of the first filter in as the input of the second filter, set those parameters, etc.
Lather, rinse, repeat for as many filters as you want.
See this link for working example code in Swift: https://www.objc.io/issues/21-camera-and-photos/core-image-intro/
Upvotes: 3