views:

118

answers:

2

Are there any nice libraries to render text in an image for Java?

Java has a 2d text library, http://java.sun.com/docs/books/tutorial/2d/text/index.html but not sure if theres a better library to use.

+3  A: 

It depends on what you want to do. Java2D is a fairly rich environment for text, as seen in the Fonts tab of the Java2D demo. Source code for the font demos may be found here. Building on this foundation, I've had good results using the text utilities in JCommon and JFreeChart. As you are annotating images, you may want to look into using AlphaComposite, also previewed in the Java2D demo.

trashgod
+2  A: 

Here's a method to draw text on an image:

public void displayText(BufferedImage image, String text, Font font, int x, int y){
   Graphics2d g = image.createGraphics();
   g.setFont(font);
   g.drawString(text, x, y);
   g.dispose();
}
Jay Askren