Compositing Graphics
Matrix transformations are nice, but you can do more with image drawing. QuickDraw supports a number of graphics modes so that instead of just copying pixels from a source to a destination, you can combine them to create interesting visual effects. The graphics mode defines the combination: blending, translucency, etc.
How do I do that?
Specifying a graphics mode for drawing is trivial. Create a
GraphicsMode object and call
setGraphicsMode( )
on the GraphicsImporter. In the included example,
GraphicImportCompositing.java, the mode is set
with the following code:
// draw foreground
GraphicsMode alphaMode =
new GraphicsMode (QDConstants.blend,
QDColor.green);
gi1.setGraphicsMode (alphaMode);Note
Run this with ant-ch05-graphic-importcompositing.
This is another headless app, producing the composite.png file as shown in Figure 5-8. Notice that where the images overlap, the 2 can now show through the 1.

Figure 5-8. Drawing with blend graphics mode
What just happened?
The “blend”
GraphicsMode instructs QuickDraw to average out
colors where they overlap. In this
case, 1’s black pixels are
lightened up by averaging when averaged with cyan, and the green is
slightly tinted where it overlaps with cyan or black.
The QDColor.green
is
irrelevant in this case, but change the first argument to
QDConstants.transparent
and
suddenly the result is very different, as shown in Figure ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access