Example usage for java.awt.geom AffineTransform getRotateInstance

List of usage examples for java.awt.geom AffineTransform getRotateInstance

Introduction

In this page you can find the example usage for java.awt.geom AffineTransform getRotateInstance.

Prototype

public static AffineTransform getRotateInstance(double theta, double anchorx, double anchory) 

Source Link

Document

Returns a transform that rotates coordinates around an anchor point.

Usage

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");
            }//  w  ww  . jav a2s. co  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 w  ww  .  j  av a  2s  .co m*/
        }
    }
}

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  .  jav  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;//  w w w .  j a  v  a  2  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:VASSAL.counters.Labeler.java

public void draw(Graphics g, int x, int y, Component obs, double zoom) {
    updateCachedImage();/*  ww w.  ja v a2s.  co m*/
    piece.draw(g, x, y, obs, zoom);

    // FIXME: We should be drawing the text at the right size, not scaling it!
    final Point p = getLabelPosition();
    final int labelX = x + (int) (zoom * p.x);
    final int labelY = y + (int) (zoom * p.y);

    AffineTransform saveXForm = null;
    final Graphics2D g2d = (Graphics2D) g;

    if (rotateDegrees != 0) {
        saveXForm = g2d.getTransform();
        final AffineTransform newXForm = AffineTransform.getRotateInstance(Math.toRadians(rotateDegrees), x, y);
        g2d.transform(newXForm);
    }

    imagePainter.draw(g, labelX, labelY, zoom, obs);

    if (rotateDegrees != 0) {
        g2d.setTransform(saveXForm);
    }
}

From source file:VASSAL.tools.image.svg.SVGRenderer.java

public BufferedImage render(double angle, double scale) {
    // The renderer needs the bounds unscaled---scaling comes from the
    // width and height hints.
    AffineTransform px = AffineTransform.getRotateInstance(angle * DEGTORAD, defaultW / 2.0, defaultH / 2.0);
    r.setTransform(px);/*from   w  ww  .j a  v a  2 s.  c o m*/

    px = new AffineTransform(px);
    px.scale(scale, scale);

    final Rectangle2D rect = new Rectangle2D.Float(0, 0, defaultW, defaultH);
    final Rectangle2D b = px.createTransformedShape(rect).getBounds2D();

    r.addTranscodingHint(Rasterizer.KEY_WIDTH, (float) b.getWidth());
    r.addTranscodingHint(Rasterizer.KEY_HEIGHT, (float) b.getHeight());

    try {
        r.transcode(new TranscoderInput(doc), null);
        return r.getBufferedImage();
    }
    // FIXME: review error message
    catch (BridgeException e) {
        logger.error("", e);
    } catch (TranscoderException e) {
        logger.error("", e);
    }

    return null;
}

From source file:VASSAL.tools.image.svg.SVGRenderer.java

public BufferedImage render(double angle, double scale, Rectangle2D aoi) {
    // The renderer needs the bounds unscaled---scaling comes from the
    // width and height hints.
    AffineTransform px = AffineTransform.getRotateInstance(angle * DEGTORAD, defaultW / 2.0, defaultH / 2.0);
    r.setTransform(px);/*from  w  ww.j a  va 2s  .  c  o m*/

    px = new AffineTransform(px);
    px.scale(scale, scale);

    final Rectangle2D rect = new Rectangle2D.Float(0, 0, defaultW, defaultH);

    r.addTranscodingHint(Rasterizer.KEY_WIDTH, (float) aoi.getWidth());
    r.addTranscodingHint(Rasterizer.KEY_HEIGHT, (float) aoi.getHeight());
    r.addTranscodingHint(Rasterizer.KEY_AOI, aoi);

    try {
        r.transcode(new TranscoderInput(doc), null);
        return r.getBufferedImage();
    }
    // FIXME: review error message
    catch (BridgeException e) {
        logger.error("", e);
    } catch (TranscoderException e) {
        logger.error("", e);
    }

    return null;
}