1

Is there a way to save a JPanel's paintComponent contents into a .png file? Preferably with java.io or some other built-in library. Thanks.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user2330570
  • 29
  • 1
  • 4

1 Answers1

6
  1. create a java.awt.image.BufferedImage
  2. get a java.awt.Graphics by BufferedImage.createGraphics()
  3. Pass the Graphics to JPanel.paintComponent()
  4. Use javax.imageio.ImageIO.write() to save it
johnchen902
  • 9,531
  • 1
  • 27
  • 69