Example usage for java.awt.image AffineTransformOp filter

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

Introduction

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

Prototype

public final WritableRaster filter(Raster src, WritableRaster dst) 

Source Link

Document

Transforms the source Raster and stores the results in the destination Raster .

Usage

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;/*www  .j ava 2  s  .  c  o  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: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   ww  w  .j  a  v a2  s.  c  o  m
        }
    }
}