I need to zero out one of the color channels in an NSImage, whats the right way to do this?

StackOverflow https://stackoverflow.com/questions/4230145

  •  26-09-2019
  •  | 
  •  

Question

I want to achieve the same result as if I were in photoshop and turned off one of the channels. I was about to try to loop through every pixel changing colors. Is there a better way to do this?

Was it helpful?

Solution

Use Core Image's Color Matrix filter. The array of vectors can be bewildering, but it's very powerful. In your case, you'll want to set the vector for the channel you want to turn off to all-zeroes.

Obviously, this will only work for RGB images, since Core Image only works for RGB images. You can make it work for gray images (turn off R, G, and B to turn off the K channel), but not for CMYK.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top