1

I have a program that acts somewhat like a light MS Paint. Currently it reads in an XML SVG description (a very limited subset of SVG) and paints the image onto a JPanel, and then the user can update the image.

I was wondering if it was possible to save this image as a PNG (saving it back to SVG is easy). I have researched this, and seen that the examples create a BufferedImage and use Graphics to paint onto the BufferedImage. I was wondering if it was possible to take everything that has already been painted/edited and immediately transfer it to a BufferedImage.

buggritall
  • 151
  • 2
  • 6

1 Answers1

1

Have you tried this? Export JPanel Graphics to .png or .gif or .jpg

I think that there is something that you don't understand about how JPanel and graphics work in Java. Asking the JPanel to draw itself in a buffer is the same as what you want to do. A JPanel isn't drawn only once. The JPanel is repainted many many times even when you only drag a window over it.

Community
  • 1
  • 1
Kaj
  • 10,862
  • 2
  • 33
  • 27