newbeee
newbeee

Reputation: 75

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

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?

Upvotes: 3

Views: 1134

Answers (1)

Micke
Micke

Reputation: 2309

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 . . .

Upvotes: 2

Related Questions