How can I determine if an image in PDF is grayscale?

Q: I have an existing process for examining grayscale images. We’ve
recently received some customer supplied files that contain either
CMYK images with only information on the black channel, or spot colour
images that print only on the black channel. Effectively, these 2
scenarios need to be treated the same as grayscale images and as such,
I need to detect them and test them the same way.

So I have 2 questions…

1) How can I detect if an image is monochrome (a spot colour) and if
it uses just the black channel.
2) How can I detect if an image contains no information on the CMY
channels, but it does use the K (black)?

When I get to the first image object, it is “element.Type.e_image”.
Using “element.GetImageColorSpace” results in “pdftron.SDF.Obj”, but
then I get an error when I try “element.GetImageColorSpace.GetName”.

What properties should I be checking?
-------------
A: You can obtain the image color space type as follows:

ColorSpace cs = element.GetImageColorSpace();
ColorSpace.Type type = cs.GetType();
if (type == ColorSpace.Type....) {
}

A monochrome image is usually represented using ‘e_device_gray’ color
space, but you may run into images in any color space that are using
only gray colors.

The only way to check with certainty if an image is grayscale is to
inspect the image data. As a starting point in this direction you may
want to take a look at ImageExtract (http://www.pdftron.com/net/
samplecode.html#ImageExtract) sample project. For example, you could
extract image in RGB format using element.GetBitmap() and then check
if there is any pixel where R/G/B components differ. If necessary, it
is also possible to extract raw CMYK data from images stored using
CMYK color space.