The Rendering Pipeline
One
of
the strengths of the 2D API is that
shapes, text, and images are
manipulated in many of the same ways. In this section, we’ll
describe what happens to shapes, text, and images after you give them
to a Graphics2D. Rendering is
the process of taking some collection of shapes, text, and images and
figuring out how to represent them by coloring pixels on a screen or
printer. Graphics2D supports four rendering
operations:
Draw the outline of a shape, with the
draw( )method.Fill the interior of a shape, with the
fill( )method.Draw some text, with the
drawString( )method.Draw an image, with any of the many forms of the
drawImage( )method.
The graphics
context instantiated by a Graphics2D object
consists of the following fields, whose values are controlled by
various accessor methods:
- paint
The current paint (an object of type
java.awt.Paint) determines what colors will be used to fill a shape. This affects shape outlines and text, as well. You can change the current paint usingGraphics2D’ssetPaint( )method. Note that theColorclass implements thePaintinterface, so you can passColors tosetPaint( )if you want to use solid colors.- stroke
Graphics2Duses the current stroke for shapes that are passed to itsdraw( )method. The outline of the shape is represented by another shape that is determined by the current stroke. The resulting shape (the stroked outline) is then filled. Suppose you wanted to draw the outline of a circle. If the current stroke ...
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