2016-09-21 32 views
0

我需要獲取eps文件的寬度和高度。c#meta data extractor for eps文件

我試圖https://github.com/drewnoakes/metadata-extractor

,但它並不適用於EPS文件的工作。

所以我用exiftool.exe並在程序上運行它。

但程序很慢。因爲它爲每個eps文件運行程序(exiftool.exe)。

是否有任何方法使用以獲得eps文件的寬度和高度更快?謝謝

下面是我得到的圖像

System.Diagnostics.Process pProcess = new System.Diagnostics.Process(); 
          string filename = tempPath; 
          pProcess.StartInfo.FileName = System.IO.Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]) + "\\exiftool.exe"; 
          string toolPath = @"" + "\"" + filename + "\""; 
          pProcess.StartInfo.Arguments = toolPath; 
          pProcess.StartInfo.CreateNoWindow = true; 
          pProcess.StartInfo.UseShellExecute = false; 
          pProcess.StartInfo.RedirectStandardOutput = true; 
          pProcess.Start(); 
          string strOutput = pProcess.StandardOutput.ReadToEnd(); 
          pProcess.WaitForExit(); 
          string source = strOutput; 

先生的寬度和高度的代碼,如果我將其轉換爲EPS文件我需要設置其密度高質量的轉換圖像。如果我那樣做。轉換圖像的高度和寬度將不相同。我使用ImageMagick DLL。爲了那個原因。並且該鏈接還運行一個exe文件。這也將拖慢程序

+0

可能的[如何獲取.ai或.eps文件的屬性?]的副本(http://stackoverflow.com/questions/12409452/how-to-get-the-properties-of-an-ai - 或 - eps文件) –

+0

先生,如果我將其轉換爲eps文件,我需要設置其密度良好的質量轉換後的圖像。如果我那樣做。轉換圖像的高度和寬度將不相同。 –

+0

http://stackoverflow.com/questions/24971184/extract-image-file-metadata –

回答

2

我不知道這是否會爲你工作,而是一種EPS具有標籤

%%BoundingBox: 0 0 350 350 

如果你讀,你可以使用這個文件。

var eps = File.ReadAllLines(path).FirstOrDefault(l => l.StartsWith("%%BoundingBox:")); 
if (eps != null) 
{ 
    var dimensions = eps.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries) 
     .ToList() 
     .Skip(1) 
     .Select(s => Convert.ToInt32(s)) 
     .ToList(); 
    var width = dimensions[2] - dimensions[0]; 
    var height = dimensions[3] - dimensions[1]; 
    Console.WriteLine($"{width} {height}"); 
} 

你可以優化這種不讀取整個文件作爲邊框爲開頭。

+0

。謝謝 –

+0

不錯。似乎你熟悉EPS。想爲它添加對[metadata-extractor-dotnet](https://github.com/drewnoakes/metadata-extractor-dotnet)的支持嗎? –

+0

@DrewNoakes我只知道我在5分鐘內搜索到了什麼:) –