Save image from a jLabel to a PC using a JFileChooser

0

I have a development in JAVA that stores images in a database, and you can view them again, I need your help, because with a button I want the image that is selected from the table to be saved in the PC.

When a row of the table is selected, the image of the selected row is automatically loaded to jLabel , what I need is that with a button invoke a JFileChooser and save the image of jLabel in the route that the user wants.

I have currently done the following:

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        JFileChooser guardarComo = new JFileChooser();
        guardarComo.setApproveButtonText("guardar");
        guardarComo.showSaveDialog(null);
        //File archivo = new File(guardarComo.getSelectedFile()+".jpg");
        File archivo = new File(guardarComo.getIcon(null)+".jpg");
        File fichero = new File("foto.jpg");
        String formato = "jpg";

        try {

             BufferedImage imagen = ImageIO.read(new File(jLabel3 +".jpg"));
             Graphics g = imagen.getGraphics();
             imagen = (BufferedImage) jLabel3.getIcon();
             ImageIO.write(imagen, formato, fichero);
        }catch (Exception e){

        }

    }   
    
asked by uriel 10.06.2018 в 07:59
source

0 answers