Hi,
I found the problem, but I'm still not sure what's causing it and if this is a Ghostscript.NET bug / problem.
The workaround would be to clone an Image returned by the GhostscriptRasterizer and then add it to the Tiff.
Here is the code sample that implements Image cloning and this way I find it works correctly:
Cheers,
Josip
I found the problem, but I'm still not sure what's causing it and if this is a Ghostscript.NET bug / problem.
The workaround would be to clone an Image returned by the GhostscriptRasterizer and then add it to the Tiff.
Here is the code sample that implements Image cloning and this way I find it works correctly:
private MemoryStream CreateTiffStream(GhostscriptRasterizer rasterizer)
{
var stream = new MemoryStream();
var encoder = ImageCodecInfo.GetImageEncoders().First(a => a.MimeType == "image/tiff");
Image img = null;
Image page;
for (int pageNumber = 1; pageNumber <= rasterizer.PageCount; pageNumber++)
{
if (pageNumber == 1)
{
img = rasterizer.GetPage(_settings.Resolution.X, _settings.Resolution.Y, pageNumber);
img = img.Clone() as Image;
img.Save(stream, encoder, GetNewImageEncoderParameters());
}
else
{
page = rasterizer.GetPage(_settings.Resolution.X, _settings.Resolution.Y, pageNumber);
page = page.Clone() as Image;
img.SaveAdd(page, GetAddPageEncoderParameters());
}
}
img.SaveAdd(GetFlushImageEncoderParameters());
stream.Seek(0, SeekOrigin.Begin);
return stream;
}
I hope this workaround helps until I find a proper solution.Cheers,
Josip