Understanding the PDF file Format – 3 types of Image Mask

The PDF Mask features offer a whole set of functionality to allow complicated image drawing to happen. Rather than just sticking an image on the page (over-writing whatever was underneath), Masks allow sophisticated use of transparency so that the image can be blended into the page and colours or areas can be wholly of partly transparent.

The simplest form of Mask is an ImageMask. This is a one bit image where each pixel is either transparent (and you can see what is behind it) or painted in the current colour. It is rather like a stencil (which lets paint through the holes but stops paint appearing elsewhere).

An ImageMask is easy to create – it is a 1bit XObject image which has a value of /ImageMask set to true. They are limited to a single colour however. So you can also have a proper Mask for more control.

A Mask allows you to specify an image which can contain transparent elements. The Mask is an object attached to the XObject. You can either specify a range of colours (which will become transparent in the image) or add a separate bitmap which can define each pixel as transparent or visible (a bit like an ImageMask but offering more flexibility).

Most flexible of all, you can have a soft Mask (SMask object) attached to the image. This does not just switch transparency on or off but lets you control how much of the image shows through – allowing alsorts of transparency.

Masks are really powerful features – if you have not tried them before, they are well worth experimenting with. What do you use Masks for?

This post is part of our “Understanding the PDF File Format” series. In each article, we aim to take a specific PDF feature and explain it in simple terms. If you wish to learn more about PDF, we have 13 years worth of PDF knowledge and tips, so click here to visit our series index!

Related Posts:

The following two tabs change content below.

Mark Stephens

System Architect and Lead Developer at IDRSolutions
Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.
Markee174

About Mark Stephens

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.

He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>