Question

I have a problem were I need to detect if a WebImage is in CMYK-mode. Either by passing the WebImage to the function, or byte-array.

At the moment I have:

public static bool IsCMYK(Image img)
{
    bool isCMYK;

    if ((GetImageFlags(img).IndexOf("Ycck") > -1) || (GetImageFlags(img).IndexOf("Cmyk") > -1))
        isCMYK = true; 
    else
        isCMYK = false;

    return isCMYK;
}

public static string GetImageFlags(Image img)
{
  var flagVals = (ImageFlags)Enum.Parse(typeof(ImageFlags), img.Flags.ToString());

  return flagVals.ToString();
}

Modified code from http://www.maxostudio.com/Tut_CS_CMYK.cfm

Not sure if its best practise or not.

How do I modify this code to detect CMYK from WebImage or byte array?

Was it helpful?

Solution

I solved it by using this code:

public static bool IsCMYK(Image image)
{
     var flags = (ImageFlags)image.Flags;
     if (flags.HasFlag(ImageFlags.ColorSpaceCmyk) || flags.HasFlag(ImageFlags.ColorSpaceYcck))
     {
         return true;
     }

     const int PixelFormat32bppCMYK = (15 | (32 << 8));
     return (int)image.PixelFormat == PixelFormat32bppCMYK;
} 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top