Displaying Graphics with Graphics2D |
You can use theGraphics2D
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 aRenderingHints
object and pass it intoGraphics2D
setRenderingHints.
If you just want to set one hint, you can callGraphics2D
setRenderingHint
and specify the key-value pair for the hint you want to set. (The key-value pairs are defined in theRenderingHints
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--can be set to default, quality, or speed.
- Antialiasing--can be set to default, on, or off.
- Color Rendering-can be set to default, quality, or speed.
- Dithering--can be set to default, disable, or enable.
- Fractional Metrics--can be set to default, on, or off.
- Interpolation--can be set to nearest-neighbor, bilinear, or bicubic.
- Rendering--can be set to default, quality, or speed.
- Text antialiasing--can be set to default, on, or off.
When a hint is set to default, the platform rendering default is used is used.
Displaying Graphics with Graphics2D |