Example usage for java.awt.image AffineTransformOp TYPE_BILINEAR

List of usage examples for java.awt.image AffineTransformOp TYPE_BILINEAR

Introduction

In this page you can find the example usage for java.awt.image AffineTransformOp TYPE_BILINEAR.

Prototype

int TYPE_BILINEAR

To view the source code for java.awt.image AffineTransformOp TYPE_BILINEAR.

Click Source Link

Document

Bilinear interpolation type.

Usage

From source file:paintbasico2d.VentanaPrincipal.java

private void jButtonAchicarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAchicarActionPerformed
    VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame());
    if (vi != null) {
        BufferedImage ImgSource = vi.getLienzo().getImage();

        if (ImgSource != null) {
            AffineTransform at = AffineTransform.getScaleInstance(0.75, 0.75);
            try {
                AffineTransformOp atop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
                BufferedImage imgdest = atop.filter(ImgSource, null);
                vi.getLienzo().setImage(imgdest);
                vi.getLienzo().repaint();
            } catch (Exception e) {
                System.err.println("error");
            }//  ww w  .  j  a  v  a  2s .c om
        }
    } // TODO add your handling code here:
}

From source file:paintbasico2d.VentanaPrincipal.java

private void jButton180gradosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton180gradosActionPerformed
    VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame());
    if (vi != null) {
        BufferedImage ImgSource = vi.getLienzo().getImage();

        if (ImgSource != null) {
            double r = Math.toRadians(180);
            Point p = new Point(ImgSource.getWidth() / 2, ImgSource.getHeight() / 2);
            AffineTransform at = AffineTransform.getRotateInstance(r, p.x, p.y);

            try {

                AffineTransformOp atop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
                BufferedImage imgdest = atop.filter(ImgSource, null);
                vi.getLienzo().setImage(imgdest);
                vi.getLienzo().repaint();
            } catch (Exception e) {
                System.err.println("error");
            }/*  ww  w  .  j a  va 2 s . c  o  m*/
        }
    }
}

From source file:paintbasico2d.VentanaPrincipal.java

private void jButton270gradosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton270gradosActionPerformed
    // TODO add your handling code here:
    VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame());
    if (vi != null) {
        BufferedImage ImgSource = vi.getLienzo().getImage();

        if (ImgSource != null) {
            double r = Math.toRadians(270);
            Point p = new Point(ImgSource.getWidth() / 2, ImgSource.getHeight() / 2);
            AffineTransform at = AffineTransform.getRotateInstance(r, p.x, p.y);

            try {

                AffineTransformOp atop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
                BufferedImage imgdest = atop.filter(ImgSource, null);
                vi.getLienzo().setImage(imgdest);
                vi.getLienzo().repaint();
            } catch (Exception e) {
                System.err.println("error");
            }//from www .j  a  v a  2s.c  om
        }
    }
}

From source file:paintbasico2d.VentanaPrincipal.java

private void jButton90gradosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton90gradosActionPerformed
    VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame());
    if (vi != null) {
        BufferedImage ImgSource = vi.getLienzo().getImage();

        if (ImgSource != null) {
            double r = Math.toRadians(90);
            Point p = new Point(ImgSource.getWidth() / 2, ImgSource.getHeight() / 2);
            AffineTransform at = AffineTransform.getRotateInstance(r, p.x, p.y);

            try {

                AffineTransformOp atop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
                BufferedImage imgdest = atop.filter(ImgSource, null);
                vi.getLienzo().setImage(imgdest);
                vi.getLienzo().repaint();
            } catch (Exception e) {
                System.err.println("error");
            }/* w  w  w. j a v  a  2s. c om*/
        }
    }
}

From source file:paintbasico2d.VentanaPrincipal.java

private void jSliderRotacionStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSliderRotacionStateChanged
    VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame());
    if (vi != null) {
        BufferedImage ImgSource = vi.getLienzo().getImage();
        if (img == null)
            img = ImgSource;//from w w w  .  j a va2 s . co m
        if (ImgSource != null) {

            try {
                double r = Math.toRadians(jSliderRotacion.getValue());
                Point p = new Point(img.getWidth(null) / 2, img.getWidth(null) / 2);
                AffineTransform at = AffineTransform.getRotateInstance(r, p.x, p.y);
                AffineTransformOp atop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
                BufferedImage imgdest = atop.filter(img, null);
                vi.getLienzo().setImage(imgdest);
                vi.getLienzo().repaint();
            } catch (Exception e) {
                System.err.println("error");
            }
        }
    }
}

From source file:ucar.unidata.idv.ui.ImageGenerator.java

/**
 * Scale the given {@code source} {@link Image}.
 *
 * @param source Source image./*from  ww w .j av  a2 s.c o  m*/
 * @param width New width.
 * @param height New height.
 *
 * @return Scaled {@code source} image (uses bilinear interpolation).
 */
public static BufferedImage getScaledImage(Image source, int width, int height) {
    // convert the given Image into a BufferedImage if needed--makes things a
    // little easier.
    BufferedImage image;
    if (source instanceof BufferedImage) {
        image = (BufferedImage) source;
    } else {
        image = new BufferedImage(source.getWidth(null), source.getHeight(null), BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = image.createGraphics();
        g.drawImage(source, 0, 0, null);
        g.dispose();
    }

    int imageWidth = image.getWidth();
    int imageHeight = image.getHeight();
    double scaleX = (double) width / imageWidth;
    double scaleY = (double) height / imageHeight;
    AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY);
    BufferedImageOp op = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR);
    return op.filter(image, new BufferedImage(width, height, image.getType()));
}