Hello there,
I am having some issues with PdfSharp not scaling Greyscale images (image.gdiImage.PixelFormat=Format8bppIndexed) correctly to a given Rect using the XGraphics.DrawImage(image, rect) method.
Basically it looks like this:
But should look like this (example only):
I changed the code below, and this seems to have fixed the issue but I don't know if this may break something else and still don't understand exactly why this is occurring. Please help so I can fix this properly.
PdfImage.csInitializeJpeg() method. Line 183 in my version of PdfSharp.Refer to code within
else if statement.
Code:
<code snippet>...
#if GDI
if ((image.gdiImage.Flags & ((int)ImageFlags.ColorSpaceCmyk | (int)ImageFlags.ColorSpaceYcck)) != 0)
{
// TODO: Test with CMYK JPEG files
// THHO: I only found ImageFlags.ColorSpaceYcck JPEG files ...
Elements[Keys.ColorSpace] = new PdfName("/DeviceCMYK");
if ((image.gdiImage.Flags & (int)ImageFlags.ColorSpaceYcck) != 0)
Elements["/Decode"] = new PdfLiteral("[1 0 1 0 1 0 1 0]"); // Invert colors? Why??
}
else if ((image.gdiImage.Flags & (int)ImageFlags.ColorSpaceGray) != 0)
{
// TW 5/2/2013: /DeviceGray option below was causing images with
// .gdiImage.pixelFormat=Format8bppIndexed to not be scaled properly in PDF.
// Replaced with default /DeviceRGB and now seems to work.
//Elements[Keys.ColorSpace] = new PdfName("/DeviceGray");
Elements[Keys.ColorSpace] = new PdfName("/DeviceRGB");
}
else
{
Elements[Keys.ColorSpace] = new PdfName("/DeviceRGB");
}
Kind Regards
Travis