Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

DynaPDF Manual - Page 75

Previous Page 74   Index   Next Page 76

Transparency
Page 75 of 750
PDF Transparency
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 colour.
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
image.
Alpha Blending
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 whished 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
defaults.
Note that the functions Save/RestoreGraphicState() do not affect members of an extended graphics
state. This circumstance must be considered when creating transparent objects.
Example (C++):
int main(int argc, char* argv[])
{
pdfCreateNewPDF(PDF, "c:/cppout.pdf");
 

Previous topic: Layers (Optional Content)

Next topic: Transparency Groups / Soft Masks