save.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Rectangle rec = label.getBounds(); BufferedImage img = new BufferedImage(rec.width,rec.height,BufferedImage.TYPE_INT_ARGB); paint(img.getGraphics()); JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int result = chooser.showDialog(Form.this,"Save"); if (result == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try { ImageIO.write(img,"*.jpg", file); JOptionPane.showMessageDialog(Form.this,"The image was saved!", "",JOptionPane.INFORMATION_MESSAGE); } catch (IOException ex) { JOptionPane.showMessageDialog(Form.this,"Error!", "",JOptionPane.ERROR_MESSAGE); } } else { JOptionPane.showMessageDialog(Form.this,"Canceled by user"); } } });
Does not save, although it seems to work correctly. Help me figure out where I made a mistake.
C:/
disk, changed it toD:/
everything worked) - E1mirImageIO.write
(formatName) should be just "jpg" - zRrr