Java PNG 파일 생성

Jmnote (토론 | 기여)님의 2021년 10월 9일 (토) 19:40 판 (→‎개요)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

개요[ | ]

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"));
    }
}