IBM has an article introduces a dynamic graphic combined with the output of the output, because of this article uses Sun's JPEG special classes: com.sun.mage.codec.jpeg. *; I personally think is very versatility, using JDK1. 4 new features, it can also be made:
The dynamic graphic of my practice is hereby announced as follows from JavaBeans:
import java.io *;. import java.util *;. import java.awt.image.BufferedImage; import java.awt.Image; import java.awt.image.AffineTransformOp; import javax.imageio.ImageIO; import java.awt Import java.awt.graphics2d; import java.awt.color; import java.awt.font; .............. / / Generate bufferedImage instance, this is not required Class BUFFEREDIMAGE BI = Imageio.Read (f) using Graphics2D when real display; // Using Graphics2D's new feature. Graphics2D g2d = bi.creategraphics (); // Define font (体 or Song body, etc.) and its size font myfont = New font ("/ u5b8b / u4f53", font.plain, 20); g2d.setfont (myfont); // font color is black g2d.setcolor (color.black); // Need to write text on the picture Note: Chinese Requires operating system to support Chinese such as Chinese, to install Chinese Biling Bank, and make JDK1.4 support this Chinese string strs = "Hello Everyone Chinese"; // Write text in 20 from the top and left, The GetBytes feature of Chinese processing is used. G2D.DrawString (New String ("ISO8859_1"), 20, 20); // must be used, indicate completion of g2d.dispose (); try {// Write images Imageio.Write (Bi, EXT, THF); // It turns out the function using com.sun.codec.jpeg. *, As follows. Need to download com.sun.codec.jpeg // FileOutputStream out = new fileoutputstream (THF); // jpegimageEncoder encoder = jpegcodec.createjpegenco Der (out); // encoder.encode (bi); // out.close ();} catch (exception ex) {throw new exception ("imageio.write error in creathum .:" ex.getMessage ()) }
As long as JSP notifies this bean, it will easily generate its own graphic. The following picture I will debug on Linux. Since Linux does not have a font base, so the meaning of the picture below is not displayed, but the program I am in Chinese Win2000. The debug is normal.
Original image:
Renderings