jueves, 22 de diciembre de 2016

Procesamiento de imagenes en Java


Que tal amigos en esta ocasión les quiero compartir un programa que hice en java en el cual consisten el el procesamiento e imágenes en el cual la cual aplica varios filtros , rota la imagen a 90, permite abrir y guardar varios formatos de imágenes y los cambios que se apliquen a la imagen se puede guardar con esos cambios sin ningún problema. Les dejo algunas imágenes y el código fuente para que lo mejoren y dejen sus comentarios si nos es muchas molestia.








Clase transformar imagen que permite rotar la imagen a 90 grados

       
           package program;

/**
 * importando las librerias
 */
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;

/**
 *
 * @author Francisco Aguilar
 * @author maricarmen etc.
 */
public class TransformarImagen {

    /**
     * declaracion de variables globales
     */
    //se crea un objeto 
    AffineTransform trans;

    int alturaImagen;
    int anchoImagen;
    double grados;

    /**
     * metodo que devuelve la altura y la anchura de la imagen
     *
     * @param alturaImagen variable de tipo entero
     * @param anchuraImagen variable de tipo entero
     */
    public TransformarImagen(int alturaImagen, int anchuraImagen) {
        trans = new AffineTransform();
        this.alturaImagen = alturaImagen;
        this.anchoImagen = anchuraImagen;
    }

    /**
     * metodo que devuelve los grados
     *
     * @param grados variable de tipo double
     */
    public void rotar(double grados) {
        this.grados = grados;
        //calcula el angulo  y el punto de rotacion 
        trans.rotate(Math.toRadians(grados), anchoImagen / 2.0, alturaImagen / 2.0);
    }

    /**
     * metodo que devuelve el objeto AffineTransform llamado trans
     *
     * @return
     */
    public AffineTransform Trans() {
        return trans;
    }

    /**
     * metodo que calcula la translacion de la imagen
     */
    public void Traslacionfinal() {
        /*
         * variable de tipo point2D
         * Point2Dclase define un punto que representa una ubicación en el (x,y)espacio de coordenadas.
         */
        Point2D puntoA, puntoB;
        //calcula el ṕunto A
        puntoA = hallarPtoATraslacion();
        puntoB = trans.transform(puntoA, null);
        //variable de tipo double
        double ytrans = puntoB.getY();

        puntoA = hallarPtoBTraslacion();
        puntoB = trans.transform(puntoA, null);
        //        variable de tipo double
        double xtrans = puntoB.getX();
        //se crea un objeto nuego de tipo affine
        AffineTransform a = new AffineTransform();
        // el objeto obtiene las coordenadas de X y Y
        a.translate(-xtrans, -ytrans);
        trans.preConcatenate(a);
    }

    /**
     * metodo que obtiene el punto A
     *
     * @return devuelve un objeto de tipo point2D
     */
    private Point2D hallarPtoATraslacion() {
        Point2D puntoA;
        if (grados >= 0 && grados <= 90) {
            puntoA = new Point2D.Double(0.0, 0.0);
        } else if (grados > 90 && grados <= 180) {
            puntoA = new Point2D.Double(0.0, alturaImagen);
        } else if (grados > 180 && grados <= 270) {
            puntoA = new Point2D.Double(anchoImagen, alturaImagen);
        } else {
            puntoA = new Point2D.Double(anchoImagen, 0.0);
        }
        return puntoA;
    }

    /**
     * metodo que obtiene el punto B
     *
     * @return devuelve un Objeto de tipo point2D
     */
    private Point2D hallarPtoBTraslacion() {
        Point2D puntoB;
        if (grados >= 0 && grados <= 90) {
            puntoB = new Point2D.Double(0.0, alturaImagen);
        } else if (grados > 90 && grados <= 180) {
            puntoB = new Point2D.Double(anchoImagen, alturaImagen);
        } else if (grados > 180 && grados <= 270) {
            puntoB = new Point2D.Double(anchoImagen, 0.0);
        } else {
            puntoB = new Point2D.Double(0.0, 0.0);
        }
        return puntoB;
    }
}

       
 


Clase que permite guardar el recorte de la  imagen

       
        package program;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JLabel;
import static program.design.mos_msj;


public class RecortarImagen extends JLabel implements MouseMotionListener, MouseListener {

    /**
     *  variables generales usadas dentro de la clase
     */
    Image Original;
    BufferedImage Imagen, ImagenR;
    Graphics2D g2;
    Graphics2D g2D;
    boolean con_foto = false;

    /**
     * coordenadas y tamaño del recorte
     */
    float X = 30;
    float Y = 30;
    float clipAncho = 200;
    float clipAlto = 200;

    /**
     * define el tamaño del recorte
     * 
     */
    public void TamañoRecorte(float ancho) {
        this.clipAncho = ancho;
        clipAlto = ancho;
        repaint();
    }

    /**
     * variables para elmovimiento
     */
    private int Pos_Marca_new_X = 0;
    private int Pos_Marca_new_Y = 0;
    private int Pos_Marca_X = 0;
    private int Pos_Marca_Y = 0;
    private int Dist_X = 0;
    private int Dist_Y = 0;

    private Color color_linea = new Color(100, 0, 0);
    private float grosor_linea = 2f;

    public RecortarImagen(BufferedImage f) {
        this.Original = f;
        this.setSize(f.getWidth(), f.getHeight());
        this.setVisible(true);
        this.con_foto = true;
        //eventos del raton
        addMouseMotionListener(this);
        addMouseListener(this);
    }

    @Override
    protected void paintComponent(Graphics g) {

        g2 = (Graphics2D) g;
        if (this.con_foto) {
            //se crea un lienzo del tamaño de la foto
            Imagen = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_RGB);
            g2D = Imagen.createGraphics();
            g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            //se añade la foto grande original
            g2D.drawImage(Original, 0, 0, Original.getWidth(this), Original.getHeight(this), this);
            //se crea un recuadro que sirve de referencia para el recorte
            g2D.setStroke(new BasicStroke(this.grosor_linea));
            g2D.setColor(color_linea);
            Rectangle2D r2 = new Rectangle2D.Float(X, Y, clipAncho, clipAlto);
            g2D.draw(r2);
            //se dibuja todo
            g2.drawImage(Imagen, 0, 0, this);

        }

    }

    //se extrae una subimagen de la imagen original del tamaño del recuadro rojo
    private void recortar() {
        ImagenR = ((BufferedImage) Original).getSubimage((int) X, (int) Y, (int) clipAncho, (int) clipAlto);
    }

    //metodo que guarda la imagen en disco en formato JPG
    public void guardar_imagen(File f, String formato) {
        recortar();
        try {
            //se escribe en disco            
            ImageIO.write(ImagenR, formato, f);
           /*Mensaje*/
           mos_msj("Se guardó correctamente");
        } catch (IOException e) {
            mos_msj("No se pudo guardar");
        }
    }

    /* metodos del mouse para el cuadro de recorte */
    public void mouseDragged(MouseEvent e) {
        //nuevas coordenadas
        Pos_Marca_new_X = (int) e.getPoint().getX();
        Pos_Marca_new_Y = (int) e.getPoint().getY();

        //se obtiene distancia del movimiento
        Dist_X = Pos_Marca_new_X - Pos_Marca_X;
        Dist_Y = Pos_Marca_new_Y - Pos_Marca_Y;

        //se coloca la nueva posicion
        X = X + Dist_X;
        Y = Y + Dist_Y;

        //evita que se revace los limites de la imagen
        if (X < 0) {
            X = 0;
        }
        if (Y < 0) {
            Y = 0;
        }
        if ((X + this.clipAncho) > this.getWidth()) {
            X = this.getWidth() - this.clipAncho;
        }
        if ((Y + this.clipAlto) > this.getHeight()) {
            Y = this.getHeight() - this.clipAlto;
        }

        Pos_Marca_X = Pos_Marca_X + Dist_X;
        Pos_Marca_Y = Pos_Marca_Y + Dist_Y;
        this.repaint();
    }

    public void mouseMoved(MouseEvent e) {

    }

    public void mouseClicked(MouseEvent e) {

    }

    public void mousePressed(MouseEvent e) {
        Pos_Marca_X = (int) e.getPoint().getX();
        Pos_Marca_Y = (int) e.getPoint().getY();
    }

    public void mouseReleased(MouseEvent e) {

    }

    public void mouseEntered(MouseEvent e) {

    }

    public void mouseExited(MouseEvent e) {

    }

}

       
 

Formulario principal en donde se abre las imagenes, aqui tambien estan algunos metodos

       
          package program;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.color.ColorSpace;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ByteLookupTable;
import java.awt.image.ColorConvertOp;
import java.awt.image.ConvolveOp;
import java.awt.image.Kernel;
import java.awt.image.LookupOp;
import java.awt.image.LookupTable;
import java.awt.image.RescaleOp;
import java.awt.image.ShortLookupTable;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
import static program.design.mos_msj;

public class imagen extends javax.swing.JFrame implements ActionListener {

    /**
     *  crea un un objeto de otra clase llada RecortarImagen
     */
    RecortarImagen recorte;

    /**
     * variables globales de tipó bufferedImagen y variables de tipo entero.
     *
     */
    private BufferedImage imagen, imagen_filtro, copia;
    int w, h, opcion, grados = 0;
    double x1, y1;

    /**
     * constructor de la clase
     */
    public imagen() {
        initComponents();
        setTitle("Area Imagen");
    }

    /**
     * metodo que devuelve un valor de tipo entero.
     *
     * @param efecto
     */
    public void r_efecto(int efecto) {
        opcion = efecto;
    }

    /**
     * metodo set que recibe dos valores de tipo double
     *
     * @param x
     * @param y
     */
    public void tam(double x, double y) {
        x1 = x;
        y1 = y;
    }

    /**
     * arreglo estatico de tipo flotante para filtro sharpening
     */
    public static final float[] SHARPEN3x3 = {
        0.f, -1.f, 0.f,
        -1.f, 5.f, -1.f,
        0.f, -1.f, 0.f
    };
    /**
     * arreglo estatico de tipo flotante para filtro detectar bordes
     */
    public static final float[] valores = {
        0.0f, -1.0f, 0.0f,
        -1.0f, 4.0f, -1.0f,
        0.0f, -1.0f, 0.0f
    };
    /**
     * arreglo estatico de tipo flotante para filtro low-pass
     */
    public static final float[] BLUR3x3 = {
        0.1f, 0.1f, 0.1f,
        0.1f, 0.2f, 0.1f,
        0.1f, 0.1f, 0.1f
    };
    //variable estatica tipo short
    public static final short col = 256;
    /**
     * arreglo estatico de tipo flotante para filtro negativo
     */
    public static final short[] coloresInvertidos = new short[col];

    static {
        for (int i = 0; i < col; i++) {
            coloresInvertidos[i] = (short) ((col - 1) - i);
        }
    }
    /**
     * Arreglo para el eliminar el color rojo
     */
    static final short[] coloresSinInvertir_r = new short[col];
    static final short[] cr_cero = new short[col];

    /*Guarda azul*/
    static short[][] elimina_rojo = {
        cr_cero, coloresSinInvertir_r, coloresSinInvertir_r};

    static {
        for (int i = 0; i < col; i++) {
            coloresSinInvertir_r[i] = (short) (i);
            coloresInvertidos[i] = (short) ((col - 1) - i);
            cr_cero[i] = 0;
        }
    }

    /*Guarda rojo*/
    static short[][] elimina_azul = {
        coloresSinInvertir_r, cr_cero, coloresSinInvertir_r};

    /*Guarda Amarillo*/
    static short[][] elimina_verde = {
        coloresSinInvertir_r, coloresSinInvertir_r, cr_cero};


    /*Para ajuste de brillo*/
    public static float p = (float) 2;
    static final float[] componentes = {p, p, p};
    static final float[] desplazamientos = {0.0f, 0.0f, 0.0f};

    /**
     * Metodo para abrir la imagen con JfileChooser
     *
     * @return exportPath variable de tipo cadena
     */
    public String agregar_imagen() {

        JFileChooser file = new JFileChooser();//Objeto de tipo File Chosser para seleccionar la ruta de la imagen
        File ruta = null;// como la ruta cambia de direccion, la inicializo a null como contador

        int estado = file.showOpenDialog(null);//guardo el estado en un entero
        if (estado == JFileChooser.APPROVE_OPTION) {//Si presiono en aceptar entonces se procesa a guardar la direccion

            ruta = file.getSelectedFile();
            String exportPath = file.getSelectedFile().getAbsolutePath();
            System.out.println(exportPath);
            return exportPath;
        }
        return null;
    }//fin deñ metodo cargar imagen

    /**
     * metodo que carga la imagen al bufferedImagen ajustando el tamaño de la
     * ventana
     *
     */
    public void cargaImag() {
        try {
            String url = agregar_imagen();
            imagen = ImageIO.read(new File(url));

            w = imagen.getWidth(); // ancho
            h = imagen.getHeight(); //alto
            if (imagen.getType() != BufferedImage.TYPE_INT_RGB) {
                BufferedImage bi2
                        = new BufferedImage(imagen.getWidth(), imagen.getHeight(), BufferedImage.TYPE_INT_RGB);
                Graphics big = bi2.getGraphics();
                big.drawImage(imagen, 0, 0, w, h, null);
                imagen_filtro = copia = imagen = bi2;
                mos_msj("Imagen cargada correctamente");
            }
            this.setSize(w, h);
        } catch (IOException e) {
            mos_msj("La imagen no se pudo leer");
            //System.exit(1);
        }
    } //fin del metodo cargarimagen

    /**
     * metodo que aplica filtros sobre la imagen original
     */
    public void agrega_filtro() {
        //declaracion de un buffered image
        BufferedImageOp destino = null;
        //estructura de seleccion switch
        switch (opcion) {
            case 9:
                /* Negativo */
                LookupTable lt = new ShortLookupTable(0, coloresInvertidos);
                destino = new LookupOp(lt, null);
                break;
            case 10:
                /*Detecta bordes*/
                float[] data1 = valores;
                destino = new ConvolveOp(new Kernel(3, 3, data1), ConvolveOp.EDGE_NO_OP, null);
                break;
            case 11:
                /* aumenta escala usando transform Op e interpolacion BICUBIC */
                AffineTransform at = AffineTransform.getScaleInstance(x1, y1);
                destino = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC);
                break;
            case 12:
            /* low pass filter */
            case 13:
                /* sharpen */
                float[] data = (opcion == 12) ? BLUR3x3 : SHARPEN3x3;
                destino = new ConvolveOp(new Kernel(3, 3, data), ConvolveOp.EDGE_NO_OP, null);
                break;
            case 14:
                /* lookup */
                byte lut[] = new byte[256];
                for (int j = 0; j < 256; j++) {
                    lut[j] = (byte) (256 - j);
                }
                ByteLookupTable blut = new ByteLookupTable(0, lut);
                destino = new LookupOp(blut, null);
                break;
            default:
        }
        try {
            imagen_filtro = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
            destino.filter(imagen, imagen_filtro);
        } catch (Exception e) {
            System.out.print("");
        }

    } // fin metodo agrega filtro

    /**
     * metetodo que pinta sobre el panel
     *
     * @param g variable de tipo graphics
     */
    @Override
    public void paint(Graphics g) {
        //limpia contenido de contexto grafico
        g.clearRect(0, 0, this.getWidth(), this.getHeight());
        switch (opcion) {
            case 0:
                /*Imagen Original*/
                imagen_filtro = imagen;
                g.drawImage(imagen, 0, 0, null);
                break;
            case 1:
                /*Azul*/
                LookupTable azul = new ShortLookupTable(0, elimina_rojo);
                LookupOp az = new LookupOp(azul, null);
                imagen_filtro = az.filter(imagen, null);
                g.drawImage(imagen_filtro, 0, 0, null);
                break;
            case 2:
                /*Brillo*/
                RescaleOp rop2 = new RescaleOp(componentes, desplazamientos, null);
                imagen_filtro = rop2.filter(imagen, null);
                g.drawImage(imagen_filtro, 0, 0, null);
                break;
            case 3:
                /*Gris*/
                ColorConvertOp ccop = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
                imagen_filtro = ccop.filter(imagen, null);
                g.drawImage(imagen_filtro, 0, 0, null);
                break;
            case 4:
                /*Girar*/
                double r = Math.toRadians(grados); //se convierte a radianes lo grados
                AffineTransform a = new AffineTransform();
                a.rotate(r, this.getWidth() / 2, this.getHeight() / 2); //se asigna el angulo y centro de rotacion
                ((Graphics2D) g).setTransform(a);
                g.drawImage(imagen_filtro, 0, 0, this);
                break;
            case 5:
                /*Amarillo*/
                LookupTable amarillo = new ShortLookupTable(0, elimina_verde);
                LookupOp ye = new LookupOp(amarillo, null);
                imagen_filtro = ye.filter(imagen, null);
                g.drawImage(imagen_filtro, 0, 0, null);
                break;
            case 6:
                /*Filtro Rojo*/
                LookupTable rojo = new ShortLookupTable(0, elimina_azul);
                LookupOp ro = new LookupOp(rojo, null);
                imagen_filtro = ro.filter(imagen, null);
                g.drawImage(imagen_filtro, 0, 0, null);
                break;
            case 7:
                /*Efecto Espejo*/
                AffineTransform tx = AffineTransform.getScaleInstance(-1, 1);
                tx.translate(-copia.getWidth(null), 0);
                AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
                imagen_filtro = op.filter(imagen_filtro, null);
                g.drawImage(imagen_filtro, 0, 0, null);
                break;
            default:
                //apĺica los filtros  que estan dentro del metodo agrega_filtro
                agrega_filtro();
                g.drawImage(imagen_filtro, 0, 0, null);
                break;
        }
    }// fin de paint

    /**
     * este metodo rota la imagen recibibiendo los grados de tipo double
     * llamando los metodos rotar y translacion final de la clase transformar
     * imagen
     *
     * @param grados variable de tipo double
     * @return devuelve un objeto de tipo buffered imagen
     */
    public BufferedImage rotacionImagen(double grados) {
        //crea un objeto  transformar de la clase transformar imagen
        TransformarImagen Transformar = new TransformarImagen(imagen.getHeight(), imagen.getWidth());
        //llama al metodo rotar
        Transformar.rotar(grados);
        //llama al metodo tranlacion final
        Transformar.Traslacionfinal();
        //se crea un objeto de la clase AffineTransformOp
        AffineTransformOp nuevo = new AffineTransformOp(Transformar.Trans(), AffineTransformOp.TYPE_BILINEAR);
        /*
         createCompatibleDestImage(BufferedImage src, ColorModel destCM)
                Crea una imagen de destino puesto a cero con el tamaño y número de bandas correcta.
         */
        imagen_filtro = nuevo.createCompatibleDestImage(imagen, imagen.getColorModel());
        /*
            filter(BufferedImage src, BufferedImage dest)
            Realiza una operación con una sola entrada / salida única en una BufferedImage.
         */
        imagen = nuevo.filter(imagen, imagen_filtro);
        //retorna imagen
        return imagen;
    }

    /**
     * metodo set que actualiza el frame
     */
    public void actualiza_frame() {
        this.setSize(imagen.getWidth(), imagen.getHeight());
    }

    /**
     * metodo que modifica los grados a girar
     *
     * @param grados variable de tipo entero
     */
    public void Grados(int grados) {
        this.grados = grados;
        repaint();
    }

    /**
     * metodo que devuelve el objeto imagen filtro
     *
     * @return imagen_filtro variable de tipo bufferedImage
     */
    public BufferedImage getBi() {
        return imagen_filtro;
    }
/**
 * metodo que recorta una parte de la imagen
 */
    public void RecortarImagen() {
        recorte = new RecortarImagen(imagen_filtro);
        this.label.removeAll();
        this.label.add(recorte);

        recorte.TamañoRecorte(design.TAncho.getValue());
        design.TAncho.setMaximum(imagen_filtro.getHeight());

        this.label.repaint();

    }
/**
 * metodo que guarda el recorte 
 */
    public void GuardarRecorte() {
        String formato = (String) design.Formatos.getSelectedItem();
        File saveFile = new File("Recorte." + formato);
        JFileChooser chooser = new JFileChooser();
        chooser.setSelectedFile(saveFile);
        int rFormato = chooser.showSaveDialog(design.Formatos);
        if (rFormato == JFileChooser.APPROVE_OPTION) {
            saveFile = chooser.getSelectedFile();
            recorte.guardar_imagen(saveFile, formato);
        }
    }

    @SuppressWarnings("unchecked")
    // //GEN-BEGIN:initComponents
    private void initComponents() {

        label = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        label.setText("jLabel1");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(label, javax.swing.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(label, javax.swing.GroupLayout.DEFAULT_SIZE, 252, Short.MAX_VALUE)
        );

        pack();
    }// //GEN-END:initComponents

    @Override
    public void actionPerformed(ActionEvent e) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel label;
    // End of variables declaration//GEN-END:variables
}

       
 

Formulario  de controles en donde  hacemos cualquier proceso een la imagen
       
           package program;

/**
 * importando las librerias necesarias
 */
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFileChooser;

/**
 *
 * @author yuriani
 * @author Francisco Aguilar
 * @author Maricarmen Santos
 * @author Ivan luis Jimenez
 */
public class design extends javax.swing.JFrame {

    /*
   se crea un objeto para llamar al frame llamado imagen
     */
    imagen obj = new imagen();

    /**
     * constructor de la clase
     */
    public design() {
        setTitle("Menu principal");
        initComponents();
        filtro_manual.setEnabled(false);

    }

    @SuppressWarnings("unchecked")
    // //GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        filtro = new javax.swing.JComboBox<>();
        jPanel2 = new javax.swing.JPanel();
        girar = new javax.swing.JButton();
        ac_filtro_manual = new javax.swing.JCheckBox();
        filtro_manual = new javax.swing.JSlider();
        jPanel3 = new javax.swing.JPanel();
        RGB = new javax.swing.JComboBox<>();
        jPanel4 = new javax.swing.JPanel();
        Formatos = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        Guardar_B = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        Guardar = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenu4 = new javax.swing.JMenu();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();
        jMenuItem8 = new javax.swing.JMenuItem();
        jMenuItem9 = new javax.swing.JMenuItem();
        jMenu5 = new javax.swing.JMenu();
        jMenuItem10 = new javax.swing.JMenuItem();
        jMenuItem11 = new javax.swing.JMenuItem();
        jMenuItem12 = new javax.swing.JMenuItem();
        jMenuItem13 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Filtros", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(255, 0, 51))); // NOI18N

        filtro.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Ninguno", "LookupOp", "Sharpen", "LowPass", "Detectar Bordes", "Negativo", "Espejo" }));
        filtro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                filtroActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(filtro, 0, 288, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(filtro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Girar", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(255, 0, 51))); // NOI18N
        jPanel2.setForeground(new java.awt.Color(255, 255, 255));

        girar.setText("90 Grados");
        girar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                girarActionPerformed(evt);
            }
        });

        ac_filtro_manual.setText("Girar Manualmente");
        ac_filtro_manual.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ac_filtro_manualActionPerformed(evt);
            }
        });

        filtro_manual.setMajorTickSpacing(50);
        filtro_manual.setMaximum(360);
        filtro_manual.setPaintLabels(true);
        filtro_manual.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                filtro_manualStateChanged(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(filtro_manual, javax.swing.GroupLayout.DEFAULT_SIZE, 288, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(94, 94, 94)
                                .addComponent(girar))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(67, 67, 67)
                                .addComponent(ac_filtro_manual)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(girar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ac_filtro_manual)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(filtro_manual, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "RGB", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(255, 0, 51))); // NOI18N

        RGB.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Ninguno", "Escala de Grises", "Rojo", "Azul", "Amarillo", "Brillo" }));
        RGB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RGBActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(RGB, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(RGB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 15, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Guardar", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(255, 0, 51))); // NOI18N

        Formatos.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "bmp", "gif", "jpeg", "jpg", "png" }));
        Formatos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FormatosActionPerformed(evt);
            }
        });

        jLabel1.setText("Formato:");

        Guardar_B.setText("Guardar");
        Guardar_B.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Guardar_BActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Formatos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(Guardar_B)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Formatos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(Guardar_B))
                .addContainerGap(18, Short.MAX_VALUE))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Recortar Imagen", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(255, 0, 51))); // NOI18N

        TAncho.setMaximum(0);
        TAncho.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                TAnchoStateChanged(evt);
            }
        });

        jButton2.setText("Guardar Recorte");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(TAncho, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(71, 71, 71)
                        .addComponent(jButton2)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jButton2)
                .addGap(12, 12, 12)
                .addComponent(TAncho, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        mensaje.setBackground(new java.awt.Color(0, 0, 0));
        mensaje.setForeground(new java.awt.Color(204, 0, 51));

        jMenu1.setText("Archivo");

        jMenuItem1.setText("Abrir");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        Guardar.setText("Guardar");
        Guardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                GuardarActionPerformed(evt);
            }
        });
        jMenu1.add(Guardar);

        jMenuBar1.add(jMenu1);

        jMenu3.setText("Zoom");

        jMenu4.setText("Zoom (-)");

        jMenuItem6.setText("25%");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jMenu4.add(jMenuItem6);

        jMenuItem7.setText("50%");
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        jMenu4.add(jMenuItem7);

        jMenuItem8.setText("75%");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        jMenu4.add(jMenuItem8);

        jMenuItem9.setText("99%");
        jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem9ActionPerformed(evt);
            }
        });
        jMenu4.add(jMenuItem9);

        jMenu3.add(jMenu4);

        jMenu5.setText("Zoom (+)");

        jMenuItem10.setText("25%");
        jMenuItem10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem10ActionPerformed(evt);
            }
        });
        jMenu5.add(jMenuItem10);

        jMenuItem11.setText("50%");
        jMenuItem11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem11ActionPerformed(evt);
            }
        });
        jMenu5.add(jMenuItem11);

        jMenuItem12.setText("75%");
        jMenuItem12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem12ActionPerformed(evt);
            }
        });
        jMenu5.add(jMenuItem12);

        jMenuItem13.setText("99%");
        jMenuItem13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem13ActionPerformed(evt);
            }
        });
        jMenu5.add(jMenuItem13);

        jMenu3.add(jMenu5);

        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(mensaje, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(mensaje, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// //GEN-END:initComponents

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        try {
            //llamada del metodo cargar imagen
            obj.cargaImag();
            obj.setVisible(true);
        } catch (Exception e) {
            System.out.println("");
        }
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void filtroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filtroActionPerformed
        if (obj.isVisible()) {
            //seleccion de los filtros del combobox
            if (filtro.getSelectedItem() == "Ninguno") {
                obj.r_efecto(0);
                obj.repaint();
                mos_msj("Imagen Original");
            }
            if (filtro.getSelectedItem() == "LookupOp") {
                obj.r_efecto(14);
                obj.repaint();
                mos_msj("Se aplicó filtro LookupOp");
            }
            if (filtro.getSelectedItem() == "Sharpen") {
                obj.r_efecto(13);
                obj.repaint();
                mos_msj("Se aplicó filtro Sharpen");
            }
            if (filtro.getSelectedItem() == "LowPass") {
                obj.r_efecto(12);
                obj.repaint();
                mos_msj("Se aplicó filtro LowPass");
            }
            if (filtro.getSelectedItem() == "Detectar Bordes") {
                obj.r_efecto(10);
                obj.repaint();
                mos_msj("Filtro de marcado de bordes");
            }
            if (filtro.getSelectedItem() == "Negativo") {
                obj.r_efecto(9);
                obj.repaint();
                mos_msj("Se aplicó filtro Negativo");
            }
            if (filtro.getSelectedItem() == "Espejo") {
                obj.r_efecto(7);
                obj.repaint();
                mos_msj("Se tranformo a espejo");
            }
        }
    }//GEN-LAST:event_filtroActionPerformed

    private void girarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_girarActionPerformed
        try {
            //llamamada del metodo rotar imagen
            obj.rotacionImagen(90);
            obj.actualiza_frame();
            obj.repaint();
            mos_msj("Se giró la imagen");
        } catch (Exception e) {
            System.out.println("");
        }
    }//GEN-LAST:event_girarActionPerformed

    private void ac_filtro_manualActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ac_filtro_manualActionPerformed

        if (ac_filtro_manual.isSelected()) {
            filtro_manual.setEnabled(true);
            mos_msj("Giro manual ACTIVADO");
        } else {
            filtro_manual.setEnabled(false);
            mos_msj("Giro manual DESACTIVADO");
        }
    }//GEN-LAST:event_ac_filtro_manualActionPerformed

    private void filtro_manualStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_filtro_manualStateChanged
        //llamada del metodo grados para girar la imagen
        obj.Grados(filtro_manual.getValue());
        obj.r_efecto(4);
    }//GEN-LAST:event_filtro_manualStateChanged

    private void RGBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RGBActionPerformed
        //seleccion de los filtros del comboboxRGB
        if (RGB.getSelectedItem() == "Ninguno") {
            obj.r_efecto(0);
            obj.repaint();
            mos_msj("Imagen Original");
        }
        if (RGB.getSelectedItem() == "Escala de Grises") {
            obj.r_efecto(3);
            obj.repaint();
            mos_msj("Se aplicó escala de grises");
        }
        if (RGB.getSelectedItem() == "Azul") {
            obj.r_efecto(1);
            obj.repaint();
            mos_msj("Se aplicó filtro azul");
        }
        if (RGB.getSelectedItem() == "Rojo") {
            obj.r_efecto(6);
            obj.repaint();
            mos_msj("Se aplico filtro rojo");
        }
        if (RGB.getSelectedItem() == "Amarillo") {
            obj.r_efecto(5);
            obj.repaint();
            mos_msj("Se aplicó filtro amarillo");
        }
        if (RGB.getSelectedItem() == "Brillo") {
            obj.r_efecto(2);
            obj.repaint();
            mos_msj("Se aplicó brillo");
        }
    }//GEN-LAST:event_RGBActionPerformed

    private void FormatosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FormatosActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_FormatosActionPerformed

    private void GuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GuardarActionPerformed
        try {
            // llamada del metodo guardar
            guardar();
        } catch (IOException ex) {
            System.out.println("");
        }
    }//GEN-LAST:event_GuardarActionPerformed

    private void Guardar_BActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Guardar_BActionPerformed
        try {
            //llamada del metodo guardar
            guardar();
        } catch (IOException ex) {
            System.out.println("");
        }
    }//GEN-LAST:event_Guardar_BActionPerformed

    private void TAnchoStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_TAnchoStateChanged
        //llamada del metodo recortar imagen
        try {

            obj.RecortarImagen();
        } catch (Exception e) {
        }
    }//GEN-LAST:event_TAnchoStateChanged

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        //llamada del metodo guardar recorte
        obj.GuardarRecorte();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
        //metodo que llama al metodo tam para aplicar zoom al -%99
        obj.tam(0.75, 0.75);
        obj.r_efecto(11);

        obj.repaint();

    }//GEN-LAST:event_jMenuItem6ActionPerformed

    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
        //metodo que llama al metodo tam para aplicar zoom al  -%50
        obj.tam(0.5, 0.5);
        obj.r_efecto(11);
        obj.repaint();
    }//GEN-LAST:event_jMenuItem7ActionPerformed

    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
        //metodo que llama al metodo tam para aplicar zoom al -%25
        obj.tam(0.25, 0.25);
        obj.r_efecto(11);
        obj.repaint();
    }//GEN-LAST:event_jMenuItem8ActionPerformed

    private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem9ActionPerformed
        //metodo que llama al metodo tam para aplicar zoom al -%10:
        obj.tam(0.1, 0.1);
        obj.r_efecto(11);
        obj.repaint();
    }//GEN-LAST:event_jMenuItem9ActionPerformed

    private void jMenuItem10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem10ActionPerformed
        //metodo que llama al metodo tam para aplicar zoom al %25
        obj.tam(1.25, 1.25);
        obj.r_efecto(11);
        obj.repaint();
    }//GEN-LAST:event_jMenuItem10ActionPerformed

    private void jMenuItem11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem11ActionPerformed
        //metodo que llama al metodo tam para aplicar zoom al %50
        obj.tam(1.5, 1.5);
        obj.r_efecto(11);
        obj.repaint();
    }//GEN-LAST:event_jMenuItem11ActionPerformed

    private void jMenuItem12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem12ActionPerformed
        //metodo que llama al metodo tam para aplicar zoom al %75
        obj.tam(1.75, 1.75);
        obj.r_efecto(11);
        obj.repaint();
    }//GEN-LAST:event_jMenuItem12ActionPerformed

    private void jMenuItem13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem13ActionPerformed
        //metodo que llama al metodo tam para aplicar zoom al %99
        obj.tam(1.9, 1.9);
        obj.r_efecto(11);

        obj.repaint();
    }//GEN-LAST:event_jMenuItem13ActionPerformed

    /**
     * metodo que guarda la imagen
     *
     * @throws IOException variable IOException
     */
    public void guardar() throws IOException {
        try {

            String formato = (String) Formatos.getSelectedItem();
            File saveFile = new File("Imagen." + formato);
            JFileChooser chooser = new JFileChooser();
            chooser.setSelectedFile(saveFile);
            int rFormato = chooser.showSaveDialog(Formatos);
            if (rFormato == JFileChooser.APPROVE_OPTION) {
                saveFile = chooser.getSelectedFile();
                ImageIO.write(obj.getBi(), formato, saveFile);
                mos_msj("Se guardó correctamente");
            }
        } catch (Exception e) {
        }
    }

    public static void mos_msj(String Mensaje) {
        mensaje.setText(Mensaje);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(design.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(design.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(design.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(design.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //
      
/* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new design().setVisible(true);

            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public static javax.swing.JComboBox Formatos;
    private javax.swing.JMenuItem Guardar;
    private javax.swing.JButton Guardar_B;
    private javax.swing.JComboBox RGB;
    public static final javax.swing.JSlider TAncho = new javax.swing.JSlider();
    private javax.swing.JCheckBox ac_filtro_manual;
    private javax.swing.JComboBox filtro;
    private javax.swing.JSlider filtro_manual;
    private javax.swing.JButton girar;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem10;
    private javax.swing.JMenuItem jMenuItem11;
    private javax.swing.JMenuItem jMenuItem12;
    private javax.swing.JMenuItem jMenuItem13;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    public static final javax.swing.JLabel mensaje = new javax.swing.JLabel();
    // End of variables declaration//GEN-END:variables
}

  //
       
 

link del proyecto hecho en netbeans: procesamiento de imagenes


3 comentarios: