3

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?

newbeee
  • 75
  • 1
  • 12

1 Answers1

2

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 . . .
Micke
  • 2,251
  • 5
  • 33
  • 48
  • Thanks Micke, I need to install and check your code, one more doubt, can I check any image format using this? – newbeee Aug 19 '15 at 09:10
  • As long as ImageMagick can open the file you should be fine: `file: c:\tmp\eps\IMG_8088.jpg color space: sRGB` `file: c:\tmp\eps\temp.png color space: sRGB` – Micke Aug 19 '15 at 09:51
  • Thanks Micke for you suggestion and response. – newbeee Aug 19 '15 at 12:32
  • One more clarification, can you guide me how to install ghost-script using Nuget, I accidentally installed Ghost-script 9.14. I think Nuget is the way to include library to dot net ? – newbeee Aug 19 '15 at 17:21
  • I installed GS manually from the page i linked to, i.e. not using NuGet. – Micke Aug 19 '15 at 19:41
  • Micke I am facing some dependencies issues while running the code, the error is "Could not load file or assembly 'Magick.NET.Wrapper-x86.dll' or one of its dependencies. The specified module could not be found." – newbeee Aug 20 '15 at 03:04
  • Filenotfoundexceptionhandled, "Could not load file or assembly 'Magick.NET.Wrapper-x86.dll' or one of its dependencies. The specified module could not be found." but I have added the all dlls to the reference.... – newbeee Aug 20 '15 at 03:20
  • but before that it request me to add the following................................The type 'System.Drawing.Bitmap' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. c:\users\om nama shivaya\documents\visual studio 2010\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs – newbeee Aug 20 '15 at 03:34
  • As I said, I had to add a ref to System.Drawing (manually) to get it to work. That's what it's trying to tell you. – Micke Aug 20 '15 at 05:24
  • Micke, after adding system.drawing I am getting filenotfoundexceptionhandled as I mentioned above... – newbeee Aug 20 '15 at 06:03
  • Have you read and followed [this](https://magick.codeplex.com/documentation) document? – Micke Aug 20 '15 at 08:35
  • Micke, I tried but Its not worked for me, I just changed the target framework to 2.0. After changing 2.0 its working fine. But the result are not coming correctly for eps. For tif files its working like a charm. I have tested few images with the property image files (images-RGB.eps, images-CMYK.eps, images-Grayscale.eps) while testing eps its returning only CMYK. – newbeee Aug 20 '15 at 09:52
  • Then you should probably address that issue to the author om Magick.Net. – Micke Aug 20 '15 at 10:06
  • Thanks for your suggestion and help for my requirement. – newbeee Aug 20 '15 at 10:25
  • I also contact the author as per your suggestion, but one thing I am seeing now, that your result are containing sRGB but when I tried I am getting the CMYK result for all type of format, Hope I will get the reply/help from the author, thanks once again for your suggestion. – newbeee Aug 21 '15 at 03:47