Use the
Graphics2Dclass 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
Graphics2Dcontext, construct aRenderingHintsobject and pass it intoGraphics2Dby using thesetRenderingHintsmethod. If you just want to set one hint, you can callGraphics2DsetRenderingHintand specify the key-value pair for the hint you want to set. (The key-value pairs are defined in theRenderingHintsclass.)For example, to set a preference for antialiasing to be used if possible, you could use
setRenderingHint:public void paint (graphics g){ Graphics2D g2 = (Graphics2D)g; RenderingHints rh = new RenderingHints( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.setRenderingHints(rh); ... }
Note: Not all platforms support modification of the rendering mode, so specifying rendering hints does not guarantee that they will be used.
RenderingHintssupports the following types of hints:
Hint Key Values Antialiasing KEY_ANTIALIASINGVALUE_ANTIALIAS_ON
VALUE_ANTIALIAS_OFF
VALUE_ANTIALIAS_DEFAULTAlpha Interpolation KEY_ALPHA_INTERPOLATIONVALUE_ALPHA_INTERPOLATION_QUALITY
VALUE_ALPHA_INTERPOLATION_SPEEDVALUE_ALPHA_INTERPOLATION_DEFAULTColor Rendering KEY_COLOR_RENDERINGVALUE_COLOR_RENDER_QUALITY
VALUE_COLOR_RENDER_SPEEDVALUE_COLOR_RENDER_DEFAULTDithering KEY_DITHERINGVALUE_DITHER_DISABLE
VALUE_DITHER_ENABLE
VALUE_DITHER_DEFAULTFractional Text Metrics KEY_FRACTIONALMETRICSVALUE_FRACTIONALMETRICS_ON
VALUE_FRACTIONALMETRICS_OFFVALUE_FRACTIONALMETRICS_DEFAULTImage Interpolation KEY_INTERPOLATIONVALUE_INTERPOLATION_BICUBIC
VALUE_INTERPOLATION_BILINEARVALUE_INTERPOLATION_NEAREST_NEIGHBORRendering KEY_RENDERINGVALUE_RENDER_QUALITY
VALUE_RENDER_SPEEDVALUE_RENDER_DEFAULTStroke Normalization Control KEY_STROKE_CONTROLVALUE_STROKE_NORMALIZE
VALUE_STROKE_DEFAULTVALUE_STROKE_PUREStroke Normalization Control KEY_STROKE_CONTROLVALUE_STROKE_NORMALIZE
VALUE_STROKE_DEFAULTVALUE_STROKE_PUREText Antialiasing KEY_TEXT_ANTIALIASINGVALUE_TEXT_ANTIALIAS_ON
VALUE_TEXT_ANTIALIAS_OFFVALUE_TEXT_ANTIALIAS_DEFAULT
VALUE_TEXT_ANTIALIAS_GASP
VALUE_TEXT_ANTIALIAS_LCD_HRGB
VALUE_TEXT_ANTIALIAS_LCD_HBGR
VALUE_TEXT_ANTIALIAS_LCD_VRGB
VALUE_TEXT_ANTIALIAS_LCD_VBGRLCD Text Contrast KEY_TEXT_LCD_CONTRASTValues should be a positive integer in the range 100 to 250. A lower value (eg 100) corresponds to higher contrast text when displaying dark text on a light background. A higher value (eg 200) corresponds to lower contrast text when displaying dark text on a light background. A typical useful value is in the narrow range 140-180. If no value is specified, a system or implementation default value will be applied. When a hint is set to default, the platform rendering default is used.