PDFlib 8 Windows COM/.NET Tutorial
PDFlib 8 Windows COM/.NET Tutorial
PDFlib 8 Windows COM/.NET Tutorial
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Note In some situations <strong>PDFlib</strong> converts multi-strip TIFF images to multiple PDF images which would<br />
be masked individually. Since this is usually not intended, this kind of images will be rejected<br />
both as a mask as well as a masked target image. Also, it is important to not mix the implicit<br />
and explicit cases, i.e., don’t use images with transparent color values as mask.<br />
Note The mask must have the same orientation as the underlying image; otherwise it will be rejected.<br />
Since the orientation depends on the image file format and other factors it is difficult to detect.<br />
For this reason it is recommended to use the same file format and creation software for<br />
both mask and image.<br />
Cookbook A full code sample can be found in the Cookbook topic images/image_mask.<br />
Image masks and soft masks. Image masks are images with a bit depth of 1 (bitmaps)<br />
in which zero bits are treated as transparent: whatever contents already exist on the<br />
page will shine through the transparent parts of the image. 1-bit pixels are colorized<br />
with the current fill color.<br />
Soft masks generalize the concept of image masks to masks with more than 1 bit.<br />
They blend the image against some existing background. <strong>PDFlib</strong> accepts all kinds of single-channel<br />
(grayscale) images as soft mask. Note that only real gray-scale images are<br />
suitable as a mask, but not images with indexed (palette-based) color. They can be used<br />
the same way as image masks. The following kinds of images can be used as image<br />
masks:<br />
> PNG images<br />
> JBIG2 images<br />
> TIFF images (single- or multi-strip)<br />
> JPEG images (only as soft mask, see below)<br />
> BMP; note that BMP images are oriented differently than other image types. For this<br />
reason BMP images must be mirrored along the x axis before they can be used as a<br />
mask.<br />
> raw image data<br />
Image masks are simply opened with the mask option, and placed on the page after the<br />
desired fill color has been set:<br />
mask = p.load_image("tiff", maskfilename, "mask");<br />
p.setcolor("fill", "rgb", 1.0, 0.0, 0.0, 0.0);<br />
if (mask != -1)<br />
{<br />
p.fit_image(mask, x, y, "");<br />
}<br />
If you want to apply a color to an image without the zero bit pixels being transparent<br />
you must use the colorize option (see Section 7.1.5, »Colorizing Images«, page 186).<br />
7.1.5 Colorizing Images<br />
Similarly to image masks, where a color is applied to the non-transparent parts of an<br />
image, <strong>PDFlib</strong> supports colorizing an image with a spot color. This feature works for<br />
black and white or grayscale images.<br />
For images with an RGB palette, colorizing is only reasonable when the palette contains<br />
only gray values, and the palette index is identical to the gray value.<br />
186 Chapter 7: Importing Images and PDF Pages (Edition for <strong>COM</strong>, .<strong>NET</strong>, and REALbasic)