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

旧巷老猫 提交于 2019-12-11 03:48:28

问题


My requirement is to read the 50 more EPS files and export the property/color mode of the EPS, is this possible? the color modes are Gray-scale, RGB and CMYK. So far I tried the BitmapImage to read the EPS but I am NOT getting the luck. the BitmapImage does not read the EPS because it is vector format (I read somewhere in stack-overflow). Can any one helps me out to read the EPS file and display the format of image i.e., color of image? I tried some code please be gentle I am beginner to the programming world....

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");
}

Possible guessing to read the file format using imagemagick?


回答1:


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

I also had to add a reference to System.Drawing to get Magick.Net to work properly.

Magick.Net can be installed using 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 . . .


来源:https://stackoverflow.com/questions/32088356/how-to-read-the-property-or-color-information-of-eps-using-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!