Advertisement
franciscominajas

ABRIR GUARDAR

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