How can I save a graphics object into a bitmap or vector file format (such as a GIF or WMF) using Java 2D?

Bill Day

Some support for JPEG streams is provided in Java 2 via Java 2D, but not as a core platform API. JPEG is supported via the com.sun.image.codec.jpeg package. JPEG streams can in turn be wrapped in a FileOutputStream. Please refer to the related FAQ item on saving snapshot images for more information on using Java 2D to save JPEG files.

If you would like to save graphics using file formats besides JPEG, you should consider the Java Image I/O API. More information is available from the Image I/O homepage at: