Trail: 2D Graphics
|
Lesson: Displaying Graphics with Graphics2D
|
|
Controlling Rendering Quality
You can use the Graphics2D rendering hints attribute to
specify whether you want objects to be rendered as quickly as possible
or whether you prefer that the rendering quality be as high as
possible.
To set or change the rendering hints attribute in the Graphics2D
context, you can construct a RenderingHints object and
pass it into Graphics2D setRenderingHints.
If you just want to set one hint, you can call Graphics2D
setRenderingHint and specify the key-value pair for the
hint you want to set. (The key-value pairs are defined in the
RenderingHints class.)
For example, to set a preference for antialiasing to be used if
possible, you could use setRenderingHint:
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,aliasing);
Note:
Not all platforms support modification of the rendering mode, so
specifying rendering hints does not guarantee that they will be
used.
RenderingHints supports the following types of hints:
- Alpha interpolation--default, quality, or speed
- Antialiasing--default, on, or off
- Color rendering-default, quality, or speed
- Dithering--default, disable, or enable
- Fractional metrics--default, on, or off
- Interpolation--nearest-neighbor, bilinear, or bicubic
- Rendering--default, quality, or speed
- Text antialiasing--default, on, or off
When a hint is set to default, the platform rendering default is used is used.
|