views:

36

answers:

1

I'm creating a small image upload validator for this printing company, they need to make sure that an uploaded image has a color space of either CMYK or PMS.

This is what I'm using right now:

Image img = Image.FromStream(fupFile.PostedFile.InputStream);
ImageFlags flags = (ImageFlags)Enum.Parse(typeof(ImageFlags), img.Flags.ToString());

I can then check flags, which will contain something like "Partially Scalable | ColorSpaceCmyk | HasRealPixelSize". There's more info on it here: http://msdn.microsoft.com/en-us/library/system.drawing.imaging.imageflags.aspx

Notice that there is no flag for a PMS color space. Is there a way to check that?

Also, some files I upload, they don't have a color space flag at all. Does that mean that the color space can't be recognized?

I'm also wondering if this is a foolproof way to check the color space, or if there is a better strategy?

EDIT:

I've been looking around, and I guess you can get a lot of data from the image's metadata. http://msdn.microsoft.com/en-us/library/xddt0dz7%28v=VS.90%29.aspx

Does anyone know if the metadata contains the image's color space?

+2  A: 

PMS is not a color space, rather it is a system of color matching (PANTONE Color Matching System). I seriously doubt you will find any popular bitmap image file codecs that employ this method of encoding pixel color. Rather they will encode the PANTONE color as one of CMYK or RGB (or perhaps another color model).

Vector file formats like Postscript or PDF may embed spot colors that contain the PMS reference, however, even those formats usually need the RGB or CMYK equivalent of the PMS number.

The best method of determining an images color model is to know and understand the file format itself. It is not hard to read and parse the raw file headers to determine if the underlying data is stored as CMYK, RGB, etc...

Robust toolkits, such as Leadtools, may make this task a bit easier and more accurate than anything you will gather from .NET.

ColorEyes
Thanks for the info on PMS, I didn't know that. As for reading and parsing the raw header files, can you show me how to do that, or lead me in the right direction to a blog post that can help me out? Also, will a color space be consistent across all image types (.jpg, .gif, .png), or does each image type have different color spaces?
Steven