Convert a Graphics2D to an Image or BufferedImage

前端 未结 5 2008
野的像风
野的像风 2020-12-03 13:58

I have a little problem here.

I have an applet, where user can \"draw\" inside it. To do that, I use the java.awt.Graphics2D. But, how can I do to save the user draw

5条回答
  •  死守一世寂寞
    2020-12-03 14:35

    Use the drawImage method provided by Graphics2D and write it using ImageIO

    BufferedImage img;
    g2dObject.drawImage(img, null, 0, 0);
    ImageIO.write(img, "JPEG", new File("foo.jpg"));
    

提交回复
热议问题