Skip to main content

How can I get anti-aliased text?

2 replies [Last post]
Joined: 2006-02-14

I create my bitmap and Graphics2D object as follows:

BufferedImage img = new BufferedImage(devExtX, devExtY, BufferedImage.TYPE_INT_ARGB);
graphic = (Graphics2D) img.getGraphics();
graphic.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphic.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
graphic.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
graphic.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

But text is drawn with no anti-aliasing (does that mean it is aliased ?).

Any ideas what I am missing?

thanks - dave

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-14

How do you draw the text?

Joined: 2003-06-10

graphics2DObject.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

should work, but only as long as the graphics object exists. If you call, e.g., graphics2DObject.drawString() right after that, it should be anti-aliased.

To enable it globally is tricky. In 1.5 you set system property swing.aatext=true, however this only affects things drawn and painted by the system, not YOUR calls to drawString, which must still set the rendering hint.