Using JAI extended Java Image from: www.zdnet.com.cn August 03, 2002 21: 40java image function has been enhanced, but writes an image file to disk or returns a PNG or JPEG is still more difficult to implement. But we can use the Java Advanced Imaging (JAI) API to solve this problem. Jai can download from Sun's Java site, which is included in the Javax.imageIO package of JDK 1.4. A Installation.exe file is available in Windows to provide JAI automatic installation, while Unix and Linux are not available. Although JAI can run in pure Java mode, it also provides local libraries with Windows, Linux, and UNIX, which improves running speed. The following example is JAI installed on OS X of Apple, so we choose pure Java mode. To install JAI, you need one of the jai tar.gz file. Place three important JAR files, mlibwrapper_jai.jar, jai_codec.jar, and jai_core.jar in your classpath. We recommend placing them in your JDK's JRE / LIB / EXT directory. For Java, Jai is a strange system, unlike other aspects, there are many ways to understand, here there is only one advanced class and some auxiliary methods called JAI. The first parameter of these methods is an operation type name, so we will see this code: source = jai.create ("fileload", ..); jai.create ("extrema", src, ... Jai.Create ("Histogram", SRC, ...); In this system, you can easily add your own or third-party function, which is relatively loose on the type of type, so it uses it to develop difficulty bigger. Convert an AWT image into a png file requires the following small code: import java.awt.image; import java.awt.image.renderable.ParameterBlock; import javax.media.jai.jai; import javax.media.jai. Planarimage; ..... image img = .... OutputStream out = .... ParameterBlock PB = New parameterBlock (). Add (img); Planarimage SRC = (PlanariMage) Jai.create ("AWTIMAGE", PB) Jai.create ("Encode", SRC, OUT, "PNG", NULL); From the above example, it can be seen that there are two ways to pass parameters to the CREATE method. The new method is to use ParameterBlock contains all parameters. We use this method to implement the AWTIMAGE operation. The old method is to use a heavy-load method, and now they are not advocated, but we can use this method to achieve decoding operations. The above code will encode one image into a PNG and write it to OutputStream. To get more information about JAI, we strongly recommend you to read the guide.