Reputation: 15
I'm trying to handle the Ghostscript.NET 1.2.0.0 plugin to convert an .eps file to .bmp using a program written in C# with Windows Forms.
https://www.nuget.org/packages/Ghostscript.NET/1.2.0
My results are far from good and I'm not really able to pinpoint the cause of the problem. Here is the part of my code:
void ButtonConvertClick(object sender, EventArgs e)
{
string inputFilePath = @"C:\Users\Karlsson\Documents\SharpDevelop Projects\Converter\Converter\bin\calibration.eps";
string outputFilePath = @"C:\Users\Karlsson\Documents\SharpDevelop Projects\Converter\Converter\bin\calibration_csharp.bmp";
using (var rasterizer = new GhostscriptRasterizer())
{
rasterizer.Open(inputFilePath);
var image = rasterizer.GetPage(72,72,0);
var bmp = new Bitmap(image);
bmp.Save(outputFilePath, System.Drawing.Imaging.ImageFormat.Bmp);
pictureBox.Image = bmp;
rasterizer.Close();
}
}
The test file was the calibration.txt file, which was an image recording from the Tektronix oscilloscope.
To make the conversion possible, I changed the extension of this file from .txt to .eps.
Before I talk about the result of the conversion done by my C# code, I'll show how it is made by convert.io online converter https://convertio.co/eps-bmp/
(Here I manually changed the photo to .jpg to save on size)
The .eps converted with my C# code looks completely different - the actual horizontal image takes up a small area of a vertically oriented white sheet.
(Here I also changed manually the photo to .jpg to save on size)
rasterizer.GetPage only scales the image, while the proportion of the size of the drawing to the surrounding background is the same. I am not able to adjust the size as in the result image from convert.io. Of course, I realize that this online converter is much more advanced, however, it somehow handles this .eps file.
I decided to check out some other sample .eps files and found this page:
https://people.sc.fsu.edu/~jburkardt/data/eps/eps.html
So I took some sample .eps files and here is what I achieved with one of them (I selected mathematica.eps, a simple graph):
Of course I replaced calibration.eps with mathematica.eps in my code.
Suddenly, it turned out that my C# code using Ghostscript coped with the image and its resolution and overall size are identical to the size of this example placed as a pattern on the page.
It also turns out that the second .eps file is built a bit differently and it probably has some influence on the conversion method. But can you find an explanation as to why my code failed with the Calibration.eps file (adds a white background to the image) while it handled the second image perfectly? I don't know much about PostScript.
Upvotes: 0
Views: 93
Reputation: 9328
It's a bug in Ghostscript.NET library.
This is now patched (https://github.com/ArtifexSoftware/Ghostscript.NET/commit/814b25eb50770ee4649600911f4bbb8a5638281c)
The new library has not yet been officially released, but you can obtain the most recent source code and compile it on your own.
Upvotes: 0