I am missing the export file code, but I do not know what I need to add. I drew an image in the JPanel โ panel and I want to save this image on my desktop. What do I need to add?
JFileChooser chooser = new JFileChooser(); chooser.showOpenDialog(panel);
I added the following code to the paintComponent method:
bi = new BufferedImage(panel.getSize().width,panel.getSize().height, BufferedImage.TYPE_INT_ARGB); g = bi.createGraphics();
And then the Save button does it ... What else am I missing? Or do it wrong.
JFileChooser chooser = new JFileChooser(); chooser.showSaveDialog(panel); try{ImageIO.write(bi,"png",new File("test.png"));}catch (Exception ex) {}
source share