Print Page | Close Window

Imported Image Resolution

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=3094
Printed Date: 28 Apr 24 at 12:10PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Imported Image Resolution
Posted By: MarcoAbbate
Subject: Imported Image Resolution
Date Posted: 24 Mar 15 at 9:15AM
Hi everybody!
I'm facing a strange behaviour importing images using the function "DrawImage".
I have a JPEG image with a resolution on 150DPI.
Its dimensions are 404x275 mm.
When I import the image, the PDF page has the dimensions of 841.7x573.3 mm.
After some tests I found the dimensions of the PDF page are equal to the image dimesions IF THE IMAGE WAS AT 72DPI...
I tried to set the correct dimensions as follows, even if some functions are redundant:

            int pW=QP.ImageWidth();
            int pH= QP.ImageHeight();
            QP.SetPageDimensions(pW ,pH);
            QP.SetImageResolution(150, 150, 2);
            QP.FitImage(0, 0, pW, pH, 0, 0, 0);
            QP.SetOrigin(1);
            i = QP.DrawImage(0, 0, pW, pH);
            i = QP.SaveToFile(filePDF);

But I always get the same wrong dimensions (841.7x573.3 mm) in the output.
I tried to import JPEG, TIFF and BMP image, always with the same wrong result.
Note the images by themselves are correct, with the right ( 404x275 mm).
Do you have any hint or solution about this issue?
Thank you very much in advance!
Marco.




Replies:
Posted By: MarcoAbbate
Date Posted: 25 Mar 15 at 11:41AM
SOLUTION FOUND !!!
The problem is due to the fact that in any case the imported image is managed as it would have a resolution of 72 DPI.
In this case the PDF page takes its dimensions according to this wrong assumption.
To solve the problem it is mecessary to apply a scale factor from the default wrong 72 DPI resolution to the right one:

Note DPIres is the real image resolution...

            double ImageWidthInPoints = (double)QP.ImageWidth() / dpix * DPIres;
            double ImageHeightInPoints = (double)QP.ImageHeight() / dpiy * DPIres;
            int pW=QP.ImageWidth();
            int pH= QP.ImageHeight();
            QP.SetOrigin(1);
            i = QP.DrawImage(0, 0, pW, pH);
            float stdRes = 72;
            float PageScale = stdRes / DPIres;
            QP.SetPageDimensions((pW * PageScale), (pH * PageScale));
            QP.FitImage(0, 0, (pW * PageScale), (pH * PageScale), 0, 0, 0);
            i = QP.SaveToFile(filePDF);



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk