【问题标题】:How to read the property or color information of EPS using c#?如何使用c#读取EPS的属性或颜色信息?
【发布时间】:2015-08-19 06:50:21
【问题描述】:

我的要求是多读取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 读取文件格式?

【问题讨论】:

    标签: c# asp.net imagemagick ghostscript eps


    【解决方案1】:

    这需要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 . . .
    

    【讨论】:

    • 谢谢 Micke,我需要安装并检查您的代码,还有一个疑问,我可以使用它检查任何图像格式吗?
    • 只要ImageMagick可以打开文件就可以了:file: c:\tmp\eps\IMG_8088.jpg color space: sRGBfile: c:\tmp\eps\temp.png color space: sRGB
    • 感谢 Micke 的建议和回复。
    • 再澄清一点,你能指导我如何使用Nuget安装ghost-script,我不小心安装了Ghost-script 9.14。我认为 Nuget 是将库包含到 dot net 的方式?
    • 我从链接到的页面手动安装了 GS,即没有使用 NuGet。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 2019-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多