Java PNG 파일 생성

개요[ | ]

Java PNG 파일 생성
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
 
public class MyClass {
    public static void main(String[] args) throws IOException {
        BufferedImage bufferedImage = new BufferedImage(300, 200, BufferedImage.TYPE_INT_RGB);
        Graphics2D g = bufferedImage.createGraphics();
        g.fillRect(0, 0, 300, 100);
        g.drawString("Hello World", 120, 150);
        g.dispose();
        ImageIO.write(bufferedImage, "png", new File("myimage.png"));
    }
}