The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
Use the 使用“Graphics2D
class 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.Graphics2D
类渲染提示”属性指定是希望尽快渲染对象,还是希望渲染质量尽可能高。
To set or change the rendering hints attribute in the 要在Graphics2D
context, construct a RenderingHints
object and pass it into Graphics2D
by using the setRenderingHints
method.Graphics2D
上下文中设置或更改“渲染提示”属性,请构造一个RenderingHints
对象,并使用SetRenderingHights
方法将其传递到Graphics2D
中。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.Graphics2D
setRenderingHint
并为要设置的提示指定键值对。(The key-value pairs are defined in the (键值对在RenderingHints
class.)RenderingHights
类中定义。)
For example, to set a preference for antialiasing to be used if possible, you could use 例如,若要在可能的情况下设置要使用的抗锯齿首选项,可以使用setRenderingHint
: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); ... }
RenderingHints
supports the following types of hints:RenderingHints
支持以下类型的提示:
KEY_ANTIALIASING |
VALUE_ANTIALIAS_ON VALUE_ANTIALIAS_OFF VALUE_ANTIALIAS_DEFAULT | |
KEY_ALPHA_INTERPOLATION |
VALUE_ALPHA_INTERPOLATION_QUALITY VALUE_ALPHA_INTERPOLATION_SPEED VALUE_ALPHA_INTERPOLATION_DEFAULT | |
KEY_COLOR_RENDERING |
VALUE_COLOR_RENDER_QUALITY VALUE_COLOR_RENDER_SPEED VALUE_COLOR_RENDER_DEFAULT | |
KEY_DITHERING |
VALUE_DITHER_DISABLE VALUE_DITHER_ENABLE VALUE_DITHER_DEFAULT | |
KEY_FRACTIONALMETRICS |
VALUE_FRACTIONALMETRICS_ON VALUE_FRACTIONALMETRICS_OFF VALUE_FRACTIONALMETRICS_DEFAULT | |
KEY_INTERPOLATION |
VALUE_INTERPOLATION_BICUBIC VALUE_INTERPOLATION_BILINEAR VALUE_INTERPOLATION_NEAREST_NEIGHBOR | |
KEY_RENDERING |
VALUE_RENDER_QUALITY VALUE_RENDER_SPEED VALUE_RENDER_DEFAULT | |
KEY_STROKE_CONTROL |
VALUE_STROKE_NORMALIZE VALUE_STROKE_DEFAULT VALUE_STROKE_PURE | |
KEY_TEXT_ANTIALIASING |
VALUE_TEXT_ANTIALIAS_ON VALUE_TEXT_ANTIALIAS_OFF VALUE_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_VBGR | |
KEY_TEXT_LCD_CONTRAST |
When a hint is set to default, the platform rendering default is used.将提示设置为默认值时,将使用平台渲染默认值。