DynaPDF Manual - Page 84
Previous Page 83 Index Next Page 85
Page 84 of 821
The PDF format supports different types of transparency for images, vector graphics, and text. The
simplest type of transparency is called Color Key Masking. This kind of transparency is used to mask
areas of a specific color in an image so that they become transparent. Color Key Masking works with
a transparent color that must be specified beforehand.
Color Key Masking can produce unpredictable results with JPEG or JPEG2000 compressed images
because these filters are lossy filter. The use of a lossy filter means that the output is only an
approximation of the original data. Therefore, these filters may lead to slight changes in the color
values of image samples, possibly causing samples that were intended to be masked to be
unexpectedly painted instead, in colors slightly different from the mask color.
Another technique to mask images is the use of an explicit image mask (see AddMaskImage()). This
type of masking does not depend on the source color and produces predictable results with all kinds
of compression filters. The PDF format supports 1 bit image masks (PDF 1.3) as well as soft masks
(PDF 1.4) which can be defined as 1 bit or 8 bit grayscale image. The latter format represents
essentially the alpha channel of an image.
When inserting an image with an alpha channel DynaPDF converts the alpha channel to a soft mask
to preserve the transparency effect. The current transparency color or the value of
SetUseTransparency() does not affect such images. If an image with an alpha channel should appear
opaque then draw a rectangle in the wished background color behind the image.
It is also possible to add a separate image or soft mask to a base image with AddMaskImage(). This is
useful if the mask is stored in a separate image or if the mask uses another resolution as the base
PDF 1.4 introduced a new kind of transparency that based on alpha blending. Alpha blending
combines the backdrop and shape colors with an arbitrary opacity factor (alpha) which can be in the
range 0.0..1.0. The alpha constant can be defined separately for fillings and strokes. Note that the fill
alpha value is considered for images and text if the text draw mode is dmNormal.
The wished alpha values can be defined in an extended graphics state object that must be created
with CreateExtGState() and applied with SetExtGState(). An extended graphics state is valid until the
modified values are restored with another extended graphics state that sets the values back to their
Note that the functions Save/RestoreGraphicState() do not affect members of an extended graphics
state. This circumstance must be considered when creating transparent objects.
int main(int argc, char* argv)
Previous topic: Layers (Optional Content)
Next topic: Transparency Groups / Soft Masks