hello , im trying to get my save function on my menu bar to work right. when i hit save on the menu bar , it creates the file and everything. but the picture is blank. i cant seem to find what i did wrong.
heres my save method, it supposed to save an image of my GUI canvas , but like i said i comes up blank.
public void SaveToDisk(String file) { file = "save.png"; // need a buffered image to save the image BufferedImage bufferedImage = new BufferedImage(150, 150, BufferedImage.TYPE_INT_ARGB); Graphics g = bufferedImage.createGraphics(); this.paint(g); g.dispose(); System.out.println("Saving file to disk:" + file); try { ImageIO.write(bufferedImage, "png", new File(file)); } catch (Exception e) { System.out.println("[e] cannot save"); } } public void loadImage() { try { image = ImageIO.read(new File("save.png")); } catch (IOException ex) { System.out.println("[e] cannot load"); } }
just incase here the action listener for my save button , which im pretty sure is right
save.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println(e.getActionCommand()); canvas.SaveToDisk(""); } });