我一直在寻找解决这个问题的一天,但没有任何帮助,甚至这里的答案.文档也没有解释任何内容.
我只是想在另一个物体的方向上进行旋转.问题是位图不是围绕固定点旋转,而是围绕位图(0,0)旋转.
这是我遇到麻烦的代码:
Matrix mtx = new Matrix();
mtx.reset();
mtx.preTranslate(-centerX, -centerY);
mtx.setRotate((float)direction, -centerX, -centerY);
mtx.postTranslate(pivotX, pivotY);
Bitmap rotatedBMP = Bitmap.createBitmap(bitmap, 0, 0, spriteWidth, spriteHeight, mtx, true);
this.bitmap = rotatedBMP;
Run Code Online (Sandbox Code Playgroud)
奇怪的是,如何更改pre/ postTranslate()和float参数中的值并不重要setRotation().有人可以帮助并推动我朝着正确的方向前进吗?:)