Print Page | Close Window

DrawImage function problem

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=2296
Printed Date: 19 May 25 at 12:47PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: DrawImage function problem
Posted By: alinux
Subject: DrawImage function problem
Date Posted: 07 Jun 12 at 9:08AM
Hello,

Using DrawImage/DrawScaledImage alter image resolution (any image format) in PDF (even using ImageHorizontalResolution & ImageVerticalResolution).

Do anyone have an idea to how avoid this?

Thanks,
alinux



Replies:
Posted By: AndrewC
Date Posted: 07 Jun 12 at 2:00PM
Can you post a code sample.

PostScript and PDF scale the image to the required size so the resolution will change.  This is how it is designed to work.

What exactly are you trying to acheive ?  smaller filesize ?

Andrew.


Posted By: alinux
Date Posted: 07 Jun 12 at 5:17PM
Hi Andrew,

I'd like only to draw an image (a logo for example) into a PDF. As result I have a "pixelated" image  into the pdf.

I only load image from resources file (c# .Net) and use drawimage function. Same result with drawscaledimage function (scale level = 1):

MemoryStream ms = new MemoryStream();
Image img = ProjectName.ResourceFile.bpo_logo;
img.Save(ms, ImageFormat.Jpeg);
qp.AddImageFromVariant(ms.ToArray(), 0);
qp.SelectImage(qp.GetImageID(1));
qp.DrawImage(30, 30, qp.ImageWidth(), qp.ImageHeight());

I have the same result with all image formats (BMP, TIF, GIF, JPG, PNG).

alinux



-------------
alinux


Posted By: AndrewC
Date Posted: 08 Jun 12 at 11:53AM
ImageWidth and ImageHeight return a value in pixels so you cannot use this pixel value directly in DrawImage as it require a location in points (72 points = 1 inch)

Here is some code that will do what you need.

    QP.SetMeasurementUnits(0);

    int dpix = QP.ImageHorizontalResolution();
    int dpiy = QP.ImageVerticalResolution();

    if (dpix == 0) dpix = 72;
    if (dpiy == 0) dpiy = 72;

    int xx = QP.ImageWidth();
    int yy = QP.ImageHeight();

    double ImageWidthInPoints = (double)QP.ImageWidth() / dpix * 72.0; // assumming dpi units
    double ImageHeightInPoints = (double)QP.ImageHeight() / dpiy * 72.0;

    QP.DrawImage(0, 0, ImageWidthInPoints, ImageHeightInPoints);

Andrew.


Posted By: alinux
Date Posted: 11 Jun 12 at 7:50PM
Mea culpa.

Thank you Andrew for your explanation and your time.

alinux



-------------
alinux


Posted By: Autodidact
Date Posted: 11 Jun 12 at 10:22PM
How about using vector-logos? If the logo don't have to be in bitmap, which it rarely should/do, you could have a crisp logo scaled to any size — with a very low disk footprint.

-------------
Haakon 8o)



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