Gif4J PRO for Java - Text Rendering
Gif4J gif animation software logotype
Home Page for Gif4J Software java gif image processing products, solutions and services Products Page for java GIF image processing software Purchase java GIF image managing products Download Gif4J GIF image processing products Java imaging FAQs and Gif4J solutions support Contact Page Customer Area
Gif4J PRO java gif imaging class library logo

Text Rendering

The TextPainter java class is intended for drawing a text across the single or multiple lines on the BufferedImage(s). It can be very convenient for adding some text information to images, creation text-based watermarks etc.

The TextPainter class in its basis uses Java 2D lays and supports some Java 2D API concepts such as Paint etc.

This java class actually represents a small superstructure above Java2D and uses only a small part of Java2D functionality.

The TextPainter context contains the next attributes: font (instance of java.awt.Font), foreground paint (instance of java.awt.Color, java.awt.GradientPaint or java.awt.TexturePaint), backgroung color (instance of java.awt.Color), outline paint (instance of java.awt.Color, java.awt.GradientPaint or java.awt.TexturePaint) and antialiasing (on/off).

You can get and set these attributes using the corresponding constructors and getter/setter methods. There are 2 main rendering methods (please consult TextPainter Java API for more options):

 public BufferedImage renderString(String str);

 public BufferedImage renderText(String text, 
                                                       int width, boolean outline, boolean centralized);

The first method renders single string using the specified attributes from the TextPainter context. Size of the returned BufferedImage object is equal to visual bounds of the specified string to render.
The second method renders line-wraped to the specified width text using the specified attributes from the TextPainter context. Width of the returned BufferedImage object is equal to the specified width. Height is automatically extended to contain all text lines. Below examples demostrate some TextPainter features (see examples/TextRendering, examples/TextBanner, examples/ProductIcon1 and examples/ProductIcon2):
















Hint: To render outlined text with better quality use BOLD font instances.

Hint: It is no secret that any published on a site text information are not protected and can be easily grabbed by special scripts or even by copy/paste. You can prevent the grabbing of any privacy information (passwords, e-mails, price lists, financial reports etc.) by publishing such information as gif images. With the help of the Gif4J PRO for Java such functionality can be added easily for short time.

Note: Sometimes you can get ugly rendered text on the other platform while on your own platform text is rendered well. Such problems are usually connected with failing one or another font. You can get all supported fonts on the exact platform by calling getAllFonts() method of the GraphicsEnvironment class:

        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Font[] allfonts = ge.getAllFonts();

Gif4J java gif imaging lib (professional)
Gif4J PRO
Overview
 
Gif4J Java Color Quantizer
Overview
Quality Measurements & Benchmark Testing
Test Online
 
Gif4J PRO Tutorial
Loading GIF Images
Creating GIF Images
Creating GIF Frames
Transform GIF Images
Saving GIF Images
Watermarking
Morphing Filters
Text Rendering
 
Gif4J java gif imaging lib (light)
Gif4J LIGHT
Overview
 
Gif4J LIGHT Tutorial
Creating GIF Images
Creating GIF Frames
Saving GIF Images
 
Home |  Privacy Policy |  Legal Information 
© Gif4J Software 2004-2013