コード例 #1
0
  public void drawRenderedImage(BufferedImage img, AffineTransform at) {

    Log.d(
        "drawRenderedImage",
        "sx: "
            + at.getScaleX()
            + ", sy: "
            + at.getScaleY()
            + ", tx: "
            + at.getTranslateX()
            + ", ty: "
            + at.getTranslateY());

    Matrix m = new Matrix();
    float[] values = new float[9];
    values[Matrix.MSCALE_X] = (float) at.getScaleX();
    values[Matrix.MSCALE_Y] = (float) at.getScaleY();
    values[Matrix.MTRANS_X] = (float) at.getTranslateX();
    values[Matrix.MTRANS_Y] = (float) at.getTranslateY();
    values[Matrix.MSKEW_X] = (float) at.getShearX();
    values[Matrix.MSKEW_Y] = (float) at.getShearY();
    values[Matrix.MPERSP_2] = 1;
    m.setValues(values);

    canvas.drawBitmap(img.bm, m, paint);
  }
コード例 #2
0
  private static AffineTransform extractRotation(
      Point2D.Double pt, AffineTransform tx, boolean andTranslation) {

    tx.deltaTransform(pt, pt);
    AffineTransform rtx = AffineTransform.getRotateInstance(pt.x, pt.y);

    try {
      AffineTransform rtxi = rtx.createInverse();
      double dx = tx.getTranslateX();
      double dy = tx.getTranslateY();
      tx.preConcatenate(rtxi);
      if (andTranslation) {
        if (dx != 0 || dy != 0) {
          tx.setTransform(tx.getScaleX(), tx.getShearY(), tx.getShearX(), tx.getScaleY(), 0, 0);
          rtx.setTransform(
              rtx.getScaleX(), rtx.getShearY(), rtx.getShearX(), rtx.getScaleY(), dx, dy);
        }
      }
    } catch (NoninvertibleTransformException e) {
      return null;
    }
    return rtx;
  }