2.4. Compositing
Once the rasterizer has generated alpha values for an ideal shape, there are several ways to use them to modify the drawing surface of a Graphics2D. A compositing rule determines how the colors of a new graphics primitive are combined with the existing colors on a drawing surface, as shown in Figure 2.6.
In Figure 2.6, the alpha values are used to blend colors between the background color, white, and the color that is used to fill the shape, black. This is probably the most intuitive compositing rule, but there are other possibilities. Conceptually, at least, the rasterizer produces a set of alpha values for the new shape that is the same size as the drawing surface on which the shape will be rendered. Then this set of alpha values and the desired color of the new shape are combined, pixel by pixel, with the drawing surface. The equation that is used to combine these values is the compositing rule.
Figure 2.6. Adding to a drawing surface

For example, you might place the new shape behind the other elements on the drawing surface. The 2D API's compositing rules are covered in Chapter 5.
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