PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jun 30, 2024 10:24 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Mar 04, 2013 10:05 pm 
Offline

Joined: Mon Aug 29, 2011 2:07 am
Posts: 3
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:
Image

But should look like this (example only):
Image

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


Attachments:
goodscale.jpg
goodscale.jpg [ 17.72 KiB | Viewed 3872 times ]
badscale.jpg
badscale.jpg [ 17.78 KiB | Viewed 3872 times ]
Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 05, 2013 9:21 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
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 8)). PDFsharp works correctly under Windows XP.

Your fix probably will not work under Windows XP.

See also:
viewtopic.php?p=4456#p4456

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 07, 2013 5:49 am 
Offline

Joined: Mon Aug 29, 2011 2:07 am
Posts: 3
Thanks Thomas :D

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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 69 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group