Hello,
I have written a code to upload an Image Icon to Jlabel by JChooser and save Image Icon. "Both of them work".
But when I save the Image to given location I cannot see it after. Can you please help me to find the mistake?
JButton OpenIcon = new JButton("Open New map"); OpenIcon.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { JFileChooser chooser = new JFileChooser(); chooser.addChoosableFileFilter(new ImageFileFilter()); int returnVal = chooser.showOpenDialog(null); if(returnVal ==JFileChooser.APPROVE_OPTION){ File file =chooser.getSelectedFile(); Fpath = file.getPath(); ImageIcon Sicon = new ImageIcon(Fpath); pic.setIcon(Sicon); pic.repaint(); } } }); JButton Save = new JButton("Save New Map"); Save.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try{ Sicon = (ImageIcon) pic.getIcon(); bi = new BufferedImage(Sicon.getIconHeight(), Sicon.getIconWidth(), BufferedImage.TYPE_INT_RGB); Graphics g = bi.createGraphics(); fill = new File("outputFile"); JFileChooser chooserS = new JFileChooser(); chooserS.addChoosableFileFilter(new ImageFileFilter()); chooserS.setSelectedFile(fill); int returnVal = chooserS.showSaveDialog(null); if(returnVal == JFileChooser.APPROVE_OPTION){ ImageIO.write(bi, "JPG", fill); File filr =chooserS.getSelectedFile(); System.out.println("Save as file: " + filr.getAbsolutePath()); }else{ System.out.println("Saving was cancelled by user."); } }catch(IOException io){ io.printStackTrace(); }
I load the Image by browse JChooser, it loads and it's there. Then I want to save the Image which I just loaded. I have converted the Image Icon into BufferedImage so I can save it.
When it's saved I get messaged that the Image was saved into some folder. But when I open the given folder it's not there. Can you please help me to find why it's not working?