Saturday, December 05, 2009

Saving a BufferedImage to a PNG file

You can save a BufferedImage object using write method of the javax.imageio.ImageIO class. The signutaure of the method is like this:
public static boolean write(RenderedImage im,
String formatName,
File output)
throws IOException

Here im is the RenderedImage to be written, formatName is the String containg the informal name of the format (e.g. png) and output is the file object to be written to. An example usage of the method for PNG file format is shown below:
ImageIO.write(image, "png", file);

You can also use getReaderFormatNames method of the same class to learn available informal format names understood by the current set of registered readers.

source: java-tips.org

No comments:

Computers Add to Technorati Favorites Programming Blogs - BlogCatalog Blog Directory