如何使用c#读取EPS的属性或颜色信息?

How to read the property or color information of EPS using c#?

我的要求是再读取50个EPS文件,导出EPS的property/color模式,可以吗?颜色模式有灰度、RGB 和 CMYK。到目前为止,我尝试使用 BitmapImage 来读取 EPS,但我没有得到运气。 BitmapImage 不读取 EPS,因为它是矢量格式(我在堆栈溢出的某处读取)。任何人都可以帮助我读取 EPS 文件并显示图像格式,即图像颜色吗?我尝试了一些代码请温柔点我是编程世界的初学者....

C#

string imageloc = @"D:\Image";
string[] files = Directory.GetFiles(imageloc);
foreach (string file in files)
{
     BitmapImage source = new BitmapImage(new System.Uri(file));
     int bitsPerPixel = source.Format.BitsPerPixel;
     Console.Write("File Scanning--> " + file + "property is" +bitsPerPixel+"\n");
}

可能猜测是用imagemagick读取文件格式?

这需要 Magick.Net, which is in alpha currently. To be able to read EPS files you'll also need to install GhostScript

我还必须添加对 System.Drawing 的引用以使 Magick.Net 正常工作。

Magick.Net 可以使用 NuGet.

安装
namespace ConsoleApplication3
{
    using System;
    using System.IO;

    using ImageMagick;

    class Program
    {
        static void Main(string[] args)
        {
            foreach (var epsFile in Directory.GetFiles(@"c:\tmp\eps", "*.eps"))
            {
                using (var image = new MagickImage())
                {
                    image.Read(epsFile);

                    Console.WriteLine("file: {0}   color space: {1}", epsFile, image.ColorSpace);
                }
            }
        }
    }
}

file: c:\tmp\eps\a.eps   color space: CMYK
file: c:\tmp\eps\b.eps   color space: CMYK
file: c:\tmp\eps\c.eps   color space: CMYK
file: c:\tmp\eps\circle.eps   color space: sRGB
file: c:\tmp\eps\d.eps   color space: CMYK
file: c:\tmp\eps\e.eps   color space: CMYK
file: c:\tmp\eps\f.eps   color space: CMYK
file: c:\tmp\eps\football_logo.eps   color space: sRGB
file: c:\tmp\eps\fsu_logo.eps   color space: sRGB
file: c:\tmp\eps\g.eps   color space: CMYK
file: c:\tmp\eps\icam_logo.eps   color space: sRGB
Press any key to continue . . .