Advertisement
franciscominajas

Open and save

Feb 27th, 2014
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1.  
  2. import java.awt.Graphics;
  3. import java.awt.image.BufferedImage;
  4. import java.io.File;
  5. import javax.imageio.ImageIO;
  6. import javax.swing.ImageIcon;
  7. import javax.swing.JFileChooser;
  8. import javax.swing.filechooser.FileNameExtensionFilter;
  9.  
  10.  
  11.  
  12. /**
  13.  *
  14.  * @author FRANCISCO MINAJAS
  15.  */
  16. public class Abrir_Guardar {
  17.    
  18.    
  19.     public static File input;
  20.     public static String ruta;
  21.    
  22.     public void Imageelegida(Graphics g){
  23.         ImageIcon dibujo = new ImageIcon(new ImageIcon(getClass().getResource("/imagenes/1.jpeg")).getImage());
  24.         //ImageIcon dibujo = new ImageIcon(new ImageIcon(getClass().getResource(ruta)).getImage());
  25.         //g.drawImage(dibujo.getImage(), 0, 0, 30, 31,null);
  26.         g.drawImage(dibujo.getImage(), 0, 0, 360, 361,null);
  27.     }
  28.  
  29.      public void GuardarIma(BufferedImage bi){
  30.         JFileChooser fc = new JFileChooser();
  31.         fc.addChoosableFileFilter(new FileNameExtensionFilter("todos  archivos *.png", "png", "PNG"));
  32.         int elegido = fc.showSaveDialog(null);
  33.        
  34.         try{
  35.             if(elegido == JFileChooser.APPROVE_OPTION){
  36.                 File output = fc.getSelectedFile();
  37.                 String ubicacion = output.getAbsolutePath();
  38.                 ImageIO.write(bi, "png", new File(ubicacion));
  39.                
  40.                 if(!(ubicacion.endsWith(".png"))){
  41.                     File g = new File(ubicacion+".png");
  42.                     output.renameTo(g);
  43.                     System.out.println(output.getAbsolutePath());
  44.                 }                
  45.             }            
  46.         }catch(Exception e){
  47.             System.out.println("no se guardo");
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement