The Java Tutorials' Weblog

pageicon Tuesday Feb 13, 2007

Rendering Hints - The 2D Tutorial

Use the Text antialiasing technique to smooth the edges of text on a screen. The Java 2D™ API enables applications to specify whether this technique should be used and what algorithm to use by applying a text rendering hint to the Graphics.

Java 2D text rendering can be affected by rendering hints. The most common rendering hint blends the foreground (text) color with the onscreen background pixels at the edges of the text.

To request this hint an application must invoke the following method:

graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, 
			    RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

For more information about rendering hints available in JDK 6, see the Controlling Rendering Quality section of the 2D Graphics tutorial.

Guess what rendering hints were applied to the sample string.

Actually, the antialiasing capability was applied in the following order:

  1. Antialiasing is off.
  2. Antialiasing is on.
  3. Antialiasing using the TEXT_ANTIALIAS_GASP hint.
  4. Antialiasing using the TEXT_ANTIALIAS_LCD_HRGB hint.
Play with the font size and rendering hints to produce various visual effects. Find the complete code for this application as well as more details on antialiasing in the Displaying Antialiased Text by Using Rendering Hints section of the 2D trail.

-- Alla Redko

P.S. We are still interested in your feedback on the JSC Home page! Please see the previous blog entry and let us know what you think in the comments section.

Thanks!

-- Sharon Zakhour

Comments:

add

Posted by aditya on February 15, 2007 at 05:00 AM PST #

I look forward to trying this on our Suse platform, thanks,

Posted by Mike Fischer on March 16, 2007 at 01:49 PM PDT #

2D tutorial is now outdated because lot of queries makes error for this App when start execution.

Posted by world cup 2010 tickets on October 28, 2009 at 09:44 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed

« December 2009
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today

Feeds

Search this blog

Links

Weblog menu

Today's referrers

Today's Page Hits: 1019