3

Is there a simple method for checking if an NSImage Object contains a grayscale image?

What I am trying to do is count the number of colour and black and white pages within a pdf. As far as I can tell the only real solution to this is to render the pdf pages as images and then work from there. I didn't want to have to check every pixel if possible but so far that's all I can come up with.

Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247

1 Answers1

1

You can access the NSImage's -representations (which returns an array of NSImageRep instances) and query the returned NSImageReps for these details.

Primary NSImageRep and CGImage details of interest include:

  • assigned colorspace
  • the number of components from the image's bitmap info, bits per component, and bits per pixel.
justin
  • 104,054
  • 14
  • 179
  • 226
  • Thanks for the quick reply, I've had a look at what you have suggested but all return the same value (when the images are created from the same pdf) regardless of the colours present. I may be missing something, it happens a lot. – Chris Hattrell Dec 23 '11 at 18:46