问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/4230145/i-need-to-zero-out-one-of-the-color-channels-in-an-nsimage-whats-the-right-way