Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Graphics;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import javax.imageio.ImageIO;
- import javax.swing.ImageIcon;
- import javax.swing.JFileChooser;
- import javax.swing.filechooser.FileNameExtensionFilter;
- /**
- *
- * @author FRANCISCO MINAJAS
- */
- public class Abrir_Guardar {
- public static File input;
- public static String ruta;
- public void Imageelegida(Graphics g){
- ImageIcon dibujo = new ImageIcon(new ImageIcon(getClass().getResource("/imagenes/1.jpeg")).getImage());
- //ImageIcon dibujo = new ImageIcon(new ImageIcon(getClass().getResource(ruta)).getImage());
- //g.drawImage(dibujo.getImage(), 0, 0, 30, 31,null);
- g.drawImage(dibujo.getImage(), 0, 0, 360, 361,null);
- }
- public void GuardarIma(BufferedImage bi){
- JFileChooser fc = new JFileChooser();
- fc.addChoosableFileFilter(new FileNameExtensionFilter("todos archivos *.png", "png", "PNG"));
- int elegido = fc.showSaveDialog(null);
- try{
- if(elegido == JFileChooser.APPROVE_OPTION){
- File output = fc.getSelectedFile();
- String ubicacion = output.getAbsolutePath();
- ImageIO.write(bi, "png", new File(ubicacion));
- if(!(ubicacion.endsWith(".png"))){
- File g = new File(ubicacion+".png");
- output.renameTo(g);
- System.out.println(output.getAbsolutePath());
- }
- }
- }catch(Exception e){
- System.out.println("no se guardo");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement