Print Page | Close Window

Support for Transparent images

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=1514
Printed Date: 06 May 25 at 9:35AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Support for Transparent images
Posted By: Taher
Subject: Support for Transparent images
Date Posted: 19 Jul 10 at 4:00PM
Hi Guys,

i have already sent this email to support but in a hurry to get a quick answer therefore posting it here as well..

a) Are transparent images supported ?, we are using png files with its background being transparent, however when we load them and start drawing into the PDF, it somehow converts the transparency into a white or black background. 

b) If its supported, can you please helps us with some code snippets. If it’s not supported , do you guys know if they plan to support it in the near future?, a time frame would really help us…?



Thanks
Regards
Taher







Replies:
Posted By: deabrew
Date Posted: 24 Jul 10 at 2:53PM
Taher, we've answered directly via support with more detail. However, for those reading, a general summary of the comments are as follows:

_______________________________

a. Are transparent images supported?

As you may be aware, there are a few different ways of specifying transparency in PNG images.

The Options parameter of the AddImageFromFile function has a few useful values for PNG images:

0 = Load the image as usual
1 = Load the alpha channel as a greyscale image
2 = Load the image and alpha channel (limit alpha to 8-bit)
3 = Load the image (limit image 8-bit/channel)
4 = Load the alpha channel (limit to 8-bit/channel)
5 = Load the image with alpha channel (limit both to 8-bit/channel)
6 = Load the image and alpha channel

You would need to select an option that includes both the image and the alpha channel, so that would be 2, 5 or 6.

The choice depends on the bit depth of your source images. Some PDF viewers/processors might not be able to handle 16-bit image data for the image and/or for the alpha channel. Option 5 would be the safest, option 6 would provide the best image quality if the source had 16-bit data, and option 2 is a trade off with the image data allowed to be 16-bit while forcing only the alpha channel to 8-bit if necessary.

Internally, QPL will separate the alpha channel and the image data and create two separate PDF image objects, linked with an SMask (soft mask) entry.

You can then continue to use the image drawing functions as usual and the transparent areas will come through automatically.

Here's a quick example:

QP.DrawLine(0, 0, QP.PageWidth, QP.PageHeight);
QP.AddImageFromFile("scfloral10.png", 2);
QP.DrawImage(0, QP.PageHeight, QP.PageWidth, QP.PageHeight);
QP.SaveToFile("scfloral10.pdf");

______________

Transparency in GIF and TIFF images is not currently supported by QPL. We are constantly improving the image handling ability of the library but it's difficult to provide a time estimate for this.

______________

Regarding white/backgrounds -- in your sample DesignCMYK.pdf file the existing image has a solid white background. So the trick is to set up a transparency mask on the original image first, and then draw the new image onto a new layer behind the existing page content.

Here's a quick sample showing how this could be done:

// Load the original file
QP.LoadFromFile("DesignCMYK.pdf");

// Locate the existing image in the document
QP.FindImages;

// Select the found image
QP.SelectImage(QP.GetImageID(1));

// Set the image mask - white
QP.SetImageMaskCMYK(0, 0, 0, 0, 0, 0, 0, 0);

// Create a separate layer for the new image
QP.NewLayer;
QP.AddImageFromFile("scfloral10.png", 0);

// Draw the new image
QP.DrawImage(0, QP.PageHeight / 2, QP.PageWidth / 2, QP.PageHeight / 2);

// Move the new layer to the back
QP.MoveLayer(QP.LayerCount, 1);

// Save the combined file
QP.SaveToFile("DesignCMYK-out.pdf");



Posted By: Ingo
Date Posted: 24 Jul 10 at 5:31PM
Hi Taher!

Your questions are answered ...
So there's only our warm welcome for you
in this forum!
It's a user-user-forum here.
For special things you should contact the Debenu-guys (like Karl) directly.

Cheers, Ingo




Posted By: Taher
Date Posted: 24 Jul 10 at 9:13PM
Thanks everyone...support guys have really been helpful ..top marks for quickpdf customer service and support personnel.





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