/*
 * @(#)ImageUtil.java
 */


import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;

/**
 * Image Utility to save images as PNG file.
 *
 * @version 1.0 May 22, 2002
 * @author 	Neil Moomey
 */

public class ImageUtil {

    private static BufferedImage bi;

    /** Saves the BufferedImage as a PNG file. */
    public void savePNG(BufferedImage bi, File outputFile) {
        try {
	        ImageIO.write(bi, "png", outputFile);
        } catch (IOException e) {
            System.err.println("IOException has occurred:" + e.getMessage());
            return;
        }
	}

	/** For testing only. */
	public static void main (String[] args) {

		// Example how to use.

		File f1 = new File("original_image.png");
		try {
			bi = ImageIO.read(f1);
        } catch (IOException e) {
            System.err.println("IOException has occurred:" + e.getMessage());
            return;
        }

        // You can also create a BufferedImage like this:
        // BufferedImage bi = new BufferedImage(width , height, BufferedImage.TYPE_INT_RGB);
		// Graphics2D comp2D = bi.createGraphics();

        File f2 = new File("new_image.png");

        ImageUtil iu = new ImageUtil();
        iu.savePNG(bi,f2);
	}
}


