17.05.2014 Views

PDFlib 8 Windows COM/.NET Tutorial

PDFlib 8 Windows COM/.NET Tutorial

PDFlib 8 Windows COM/.NET Tutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

channels which are identified by name. These channels may be used to convey transparency<br />

or other information. When unassociated channels are found in a TIFF image<br />

<strong>PDFlib</strong> will by default use the first channel as alpha channel. However, you can<br />

explicitly select an unassociated alpha channel by supplying its name:<br />

image = p.load_image("tiff", filename, "alphachannelname={apple}");<br />

> PNG images may contain an associated alpha channel which will automatically be<br />

used by <strong>PDFlib</strong>.<br />

> As an alternative to a full alpha channel, PNG images may contain single transparent<br />

color values which will be honored by <strong>PDFlib</strong>. If multiple color values with an attached<br />

alpha value are given, only the first one with an alpha value below 50 percent<br />

is used.<br />

Note In addition to a full alpha channel Photoshop can create transparent backgrounds in a proprietary<br />

format which is not understood by <strong>PDFlib</strong>. In order to use such transparent images with<br />

<strong>PDFlib</strong> you must save them in Photoshop in the TIFF file format and select Save Transparency<br />

in the TIFF options dialog box.<br />

Sometimes it is desirable to ignore any implicit transparency which may be contained<br />

in an image file. <strong>PDFlib</strong>’s transparency support can be disabled with the ignoremask option<br />

when loading the image:<br />

image = p.load_image("tiff", filename, "ignoremask");<br />

Explicit transparency. The explicit case requires two steps, both of which involve image<br />

operations. First, a grayscale image must be prepared for later use as a mask. This is<br />

accomplished by loading the mask image. The following kinds of images can be used for<br />

constructing a mask:<br />

> PNG images<br />

> TIFF images: the nopassthrough option for load_image( ) is recommended to avoid<br />

multi-strip images.<br />

> raw image data<br />

Pixel values of 0 (zero) in the mask will result in the corresponding area of the masked<br />

image being painted, while high pixel values result in the background shining through.<br />

If the pixel has more than 1 bit per pixel, intermediate values will blend the foreground<br />

image against the background, providing a transparency effect.<br />

In the second step the mask is applied to another image with the masked option:<br />

mask = p.load_image("png", maskfilename, "");<br />

if (mask == -1)<br />

throw new Exception("Error: " + p.get_errmsg());<br />

String optlist = "masked=" + mask;<br />

image = p.load_image(type, filename, optlist)<br />

if (image == -1)<br />

throw new Exception("Error: " + p.get_errmsg());<br />

p.fit_image(image, x, y, "");<br />

The image and the mask may have different pixel dimensions; the mask will automatically<br />

be scaled to the image’s size.<br />

7.1 Importing Raster Images 185

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!