Is there any way to check an NSImage's color type in OBJC? I wanna know whether the image is GrayScale or RGB. Any suggestions would help, thanks~
Asked
Active
Viewed 378 times
1 Answers
0
If you can get the image's color space (possibly from its underlying CGImage) you could determine the number of components in it. If its < 3 you have a monochrome image.
However an image could still be monochrome and have a color color space.

nielsbot
- 15,922
- 4
- 48
- 73
-
Thank's a lot! I've found the solution following your advice. I can change the NSImage into NSBitmapImageRep, and there's a property called "colorSpaceName" for NSBitmapImageRep. It will return a NSString which indicates the color space type of the image. That's actually what I want! Thanks! – LYTTE_LJ Sep 17 '12 at 07:21
-
As long as you know the source of your image will always use a monochrome color space. Personally I wouldn't use the name of the color space since that could change in the future--number of components should be accurate. – nielsbot Sep 17 '12 at 17:16