2.2. The Rendering Pipeline

Graphics2D uses its internal state to decide exactly how graphics primitives are converted to pixel colors. For example, part of Graphics2D's internal state is a java.awt.Paint object, which describes the colors that should be used to fill shapes. Whenever you ask Graphics2D to fill a shape, it uses its current Paint to fill the shape.

Graphics2D's internal state is comprised of seven elements:

paint

The current paint determines what colors will be used to fill a shape. This also affects shape outlines and text, since stroked outlines and character shapes are both filled.

stroke

Graphics2D uses the current stroke for shapes that are passed to its draw() method. The stroke determines how the outline of the shape is drawn. The resulting shape (the stroked outline) is then filled.

font

Text is rendered by creating a shape that represents the characters to be drawn. The current font determines what shapes are created for a given set of characters. The resulting shape is then filled.

transformation

All primitives are geometrically transformed before they are rendered. This means that they may be moved, rotated, and stretched. Graphics2D's transformation converts primitives from User Space to Device Space. By default, Graphics2D creates a transformation that maps 72 User coordinates to one inch on the output device.

compositing rule

A compositing rule is used to determine how the colors of a primitive should be combined with existing colors on the Graphics2D ...

Get Java 2D Graphics now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.