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

时间:2015-08-19 06:50:21

标签: c# asp.net imagemagick ghostscript eps

我的要求是阅读50多个EPS文件并导出EPS的属性/颜色模式,这可能吗?颜色模式为灰度,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读取文件格式?

1 个答案:

答案 0 :(得分:2)

这需要Magick.Net,目前处于alpha状态。为了能够阅读EPS文件,您还需要安装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 . . .
相关问题