【问题标题】:rotating a matrix in one direction沿一个方向旋转矩阵
【发布时间】:2014-09-23 17:42:39
【问题描述】:

有没有办法让图像矩阵只在一个方向上旋转,即:逆时针?

这是我的旋转功能

void rotate(int x, int y) {

        this.matrix.postRotate((float) (this.startAngle - this.currentAngle),
                x, y);
    }

这是onTouch事件

case MotionEvent.ACTION_MOVE:

            ring_gear.setCurrentAngle((float) ring_gear.getAngle(
                    event.getX(), event.getY()));
            ring_gear.rotate(ring_gear.Width / 2, ring_gear.Height / 2);

            ring.setImageMatrix(ring_gear.matrix);

            ring_gear.startAngle = ring_gear.currentAngle;

【问题讨论】:

    标签: android matrix bitmap rotation image-rotation


    【解决方案1】:

    你总是在做 postRotate。这将先前的旋转连接到当前,有效地在每个移动事件上添加旋转角度。

    如果我理解您要正确执行的操作(将戒指移动到手指的位置),那么您只需要设置戒指的旋转,而不是添加它。

    替换这一行:

    this.matrix.postRotate((float) (this.startAngle - this.currentAngle), x, y);
    

    到这里:

    this.matrix.setRotation((float) (this.currentAngle), x, y);
    

    不需要不断添加角度,只需将其设置为当前状态即可。

    注意:

    另外,注意角度类型的转换。如果我没记错的话,Matrix 使用度数来计算旋转。我不确定您如何将触摸的 x/y 转换为角度,但如果您使用的是 Math.atan2,那么您应该记住 atan2 使用弧度,因此您需要确保将将角度类型转换为度数,然后再将其传递给矩阵。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多