How to identify CMYK images using C#

后端 未结 3 821
我在风中等你
我在风中等你 2020-12-31 01:32

Does anybody know how to properly identify CMYK images using C#? I found how to do it using ImageMagick, but I need a .NET solution. I found 3 code snippets online, only one

3条回答
  •  长发绾君心
    2020-12-31 02:19

    My test results are a bit different than yours.

    • Windows 7:
      • ImageFlags: ColorSpaceRgb
      • PixelFormat: PixelFormat32bppCMYK (8207)
    • Windows Server 2008 R2:
      • ImageFlags: ColorSpaceRgb
      • PixelFormat: PixelFormat32bppCMYK (8207)
    • Windows Server 2008:
      • ImageFlags: ColorSpaceYcck
      • PixelFormat: Format24bppRgb

    The following code should work:

        public static bool IsCmyk(this 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;
        }
    

提交回复
热议问题