Example usage for java.awt.geom AffineTransform clone

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

Introduction

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

Prototype

public Object clone() 

Source Link

Document

Returns a copy of this AffineTransform object.

Usage

From source file:com.liusoft.dlog4j.util.ImageUtils.java

/**
 * ???/*from   ww  w  .j  av  a2s. com*/
 * ?????
 * 3: 180
 * 6: 90
 * 8: 27090
 * @param img_fn
 * @param orient
 * @throws IOException 
 */
public static boolean rotateImage(String img_fn, int orient, String dest_fn) throws IOException {
    double radian = 0;
    switch (orient) {
    case 3:
        radian = 180.0;
        break;
    case 6:
        radian = 90.0;
        break;
    case 8:
        radian = 270.0;
        break;
    default:
        return false;
    }
    BufferedImage old_img = (BufferedImage) ImageIO.read(new File(img_fn));
    int width = old_img.getWidth();
    int height = old_img.getHeight();

    BufferedImage new_img = new BufferedImage(height, width, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = new_img.createGraphics();

    AffineTransform origXform = g2d.getTransform();
    AffineTransform newXform = (AffineTransform) (origXform.clone());
    // center of rotation is center of the panel
    double xRot = 0;
    double yRot = 0;
    switch (orient) {
    case 3:
        xRot = width / 2.0;
        yRot = height / 2.0;
    case 6:
        xRot = height / 2.0;
        yRot = xRot;
        break;
    case 8:
        xRot = width / 2.0;
        yRot = xRot;
        break;
    default:
        return false;
    }
    newXform.rotate(Math.toRadians(radian), xRot, yRot);

    g2d.setTransform(newXform);
    // draw image centered in panel
    g2d.drawImage(old_img, 0, 0, null);
    // Reset to Original
    g2d.setTransform(origXform);

    FileOutputStream out = new FileOutputStream(dest_fn);
    try {
        ImageIO.write(new_img, "JPG", out);
    } finally {
        out.close();
    }
    return true;
}

From source file:com.t_oster.visicut.misc.Helper.java

/**
* Compute the rotation angle of an affine transformation.
* Counter-clockwise rotation is considered positive.
*
* method taken from http://javagraphics.blogspot.com/
*
* @return rotation angle in radians (beween -pi and pi),
*  or NaN if the transformation is bogus.
*///  w  ww .j a v  a2  s.  co  m
public static double getRotationAngle(AffineTransform transform) {
    transform = (AffineTransform) transform.clone();
    // Eliminate any post-translation
    transform.preConcatenate(
            AffineTransform.getTranslateInstance(-transform.getTranslateX(), -transform.getTranslateY()));
    Point2D p1 = new Point2D.Double(1, 0);
    p1 = transform.transform(p1, p1);
    return Math.atan2(p1.getY(), p1.getX());
}

From source file:com.liusoft.dlog4j.action.PhotoAction.java

/**
 * /*w w w . j  a  v  a  2s  .  c o  m*/
 * @param ctx
 * @param imgURL
 * @param orient
 * @return
 * @throws IOException
 */
protected boolean rotate(HttpContext ctx, String imgURL, int orient) throws IOException {
    PhotoSaver saver = this.getPhotoSaver();
    InputStream inImg = saver.read(ctx, imgURL);
    BufferedImage old_img = (BufferedImage) ImageIO.read(inImg);
    int width = old_img.getWidth();
    int height = old_img.getHeight();
    BufferedImage new_img = new BufferedImage(height, width, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = new_img.createGraphics();

    AffineTransform origXform = g2d.getTransform();
    AffineTransform newXform = (AffineTransform) (origXform.clone());
    // center of rotation is center of the panel
    double radian = 0;
    double xRot = 0;
    double yRot = 0;
    switch (orient) {
    case 3:
        radian = 180.0;
        xRot = width / 2.0;
        yRot = height / 2.0;
    case 6:
        radian = 90.0;
        xRot = height / 2.0;
        yRot = xRot;
        break;
    case 8:
        radian = 270.0;
        xRot = width / 2.0;
        yRot = xRot;
        break;
    default:
        return false;
    }
    newXform.rotate(Math.toRadians(radian), xRot, yRot);

    g2d.setTransform(newXform);
    // draw image centered in panel
    g2d.drawImage(old_img, 0, 0, null);
    // Reset to Original
    g2d.setTransform(origXform);
    OutputStream out = saver.write(ctx, imgURL);
    try {
        ImageIO.write(new_img, "JPG", out);
    } finally {
        out.close();
    }
    return true;
}

From source file:org.apache.pdfbox.rendering.TilingPaint.java

/**
 * Not called in TexturePaint subclasses, which is why we wrap TexturePaint.
 *///from w w  w.ja v  a  2  s .  c o  m
@Override
public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds,
        AffineTransform xform, RenderingHints hints) {
    AffineTransform xformPattern = (AffineTransform) xform.clone();

    // applies the pattern matrix with scaling removed
    AffineTransform patternNoScale = patternMatrix.createAffineTransform();
    patternNoScale.scale(1 / patternMatrix.getScalingFactorX(), 1 / patternMatrix.getScalingFactorY());
    xformPattern.concatenate(patternNoScale);

    return paint.createContext(cm, deviceBounds, userBounds, xformPattern, hints);
}

From source file:org.eclipse.birt.chart.device.svg.SVGGraphics2D.java

public void transform(AffineTransform arg0) {
    transforms.concatenate((AffineTransform) arg0.clone());
}