Java Program to Implement RenderingHints API
Graphics attribute used by the Graphics2D class is java.awt.RenderingHints. This class is a mapping (a java.util.Map) from a set of rendering hint names to a set of rendering hint values. Unlike with other attributes, Graphics2D defines more than one method to set the rendering hints attribute.
- setRenderingHints() specifies a new set of hints that replaces the old set of hints.
- addRenderingHints() adds a set of hints to the existing set.
- setRenderingHint() sets the value for a single hint in the current set of hints.
Rendering hints are suggestions to Java 2D about how it should perform its rendering.
The RenderingHints class defines a number of constants whose names begin with KEY_. These constants represent the kind of hints you can give. The class also defines a number of constants whose names begin with VALUE_. These are the legal values for the various hints. The names of the VALUE constants make it clear with which hint KEY constant each value is associated. The purpose of the hints is to allow you to request that Java 2D turn a particular feature, such as antialiasing, on or off. In addition, the hints allow you to suggest what kind of speed versus quality trade-offs Java 2D should make. Remember that these are hints and suggestions to Java 2D, not commands. Not all Java 2D implementations support all the hints, and different implementations have different default values for the hints. Furthermore, the meanings of the hints are not precisely defined, so different implementations may interpret the hints differently.
The RenderingHints class defines and manages collections of keys and associated values which allow an application to provide input into the choice of algorithms used by other classes that perform rendering and image manipulation services.
the key set of the renderingHints is - Alpha blending interpolation method key Fractional metrics enable key Stroke normalization control key Color rendering quality key Dithering quality key Text-specific antialiasing enable key the values of the renderingHints is - Highest quality alpha blending methods Fractional text metrics mode Pure stroke conversion for accurate paths Highest quality color rendering mode Dithered rendering mode Antialiased text mode the entry set of the renderingHints is - Alpha blending interpolation method key=Highest quality alpha blending methods Fractional metrics enable key=Fractional text metrics mode Stroke normalization control key=Pure stroke conversion for accurate paths Color rendering quality key=Highest quality color rendering mode Dithering quality key=Dithered rendering mode Text-specific antialiasing enable key=Antialiased text mode the renderingHints contains Key KEY_TEXT_ANTIALIASING :true the renderingHints contains Value VALUE_TEXT_ANTIALIAS_ON :true the size of the renderingHints is :6 The renderingHints is empty