Java AWT BufferedImage save to PNG image file
import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class Main { public static void main(String[] args) { // draw 2D rounded rectangle with a buffered background BufferedImage buffImage = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); // obtain Graphics2D from buffImage and draw on it Graphics2D gg = buffImage.createGraphics(); gg.setColor(Color.YELLOW);/* w w w. ja va 2 s. c om*/ gg.fillRect(0, 0, 10, 10); gg.setColor(Color.BLACK); gg.drawRect(1, 1, 6, 6); try { ImageIO.write(buffImage, "png", new File( "image.png")); } catch (IOException e) { e.printStackTrace(); } } }