PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Greyscale images not scaling correctly https://forum.pdfsharp.net/viewtopic.php?f=2&t=2351 |
Page 1 of 1 |
Author: | whitet [ Mon Mar 04, 2013 10:05 pm ] | |||
Post subject: | Greyscale images not scaling correctly | |||
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.cs InitializeJpeg() 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
|
Author: | Thomas Hoevel [ Tue Mar 05, 2013 9:21 am ] |
Post subject: | Re: Greyscale images not scaling correctly |
Hi, Travis! whitet wrote: 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. AFAIK this is a fault that came with Windows Vista (and was still around with Windows 7 (maybe even Windows ). PDFsharp works correctly under Windows XP.Your fix probably will not work under Windows XP. See also: viewtopic.php?p=4456#p4456 |
Author: | whitet [ Thu Mar 07, 2013 5:49 am ] |
Post subject: | Re: Greyscale images not scaling correctly |
Thanks Thomas This is exactly what is happening to me. On XP it was working fine. Good point - I will test my change there also. Thanks for the link also - very interesting. I'm just trying to figure out which is the most elegant and sustainable fix for this. Cheers Travis |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |