Get access from code to a "Content Filter" set in IB on a NSImage


I have used for the first time a “Content Filter” on a NSImage NSImage (in IB). I have set the “False Color” filter. My problem is now, I want to get access to this filter from the code (I want to change dynamically the color of the filter). How can I do?




quick ObjC example, it’s quite straightforward, imageView is an NSImageView instance.
CoreImage is rooted in NSObject, so there is no additional framework required

CALayer *layer = [imageView layer];
        CIFilter *filter = [CIFilter filterWithName:@"CIFalseColor"];
        [filter setDefaults];
        [filter setValue:[CIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:1.0] forKey:@"inputColor0"];
        [filter setValue:[CIColor colorWithRed:1.0 green:0.0 blue:1.0 alpha:1.0] forKey:@"inputColor1"];
        [layer setFilters:@[filter]];

Hi Stefan,

I was trying something like this, but got:

Did I miss something?


Yes, I have to #import <QuartzCore/QuartzCore.h> and add this framework to my project.

Now it works. Thanks a lot! I could have defined a complex bezier path and set a color, but I wanted to try something new!