相关疑难解决方法(0)

Android:如何在中心点上旋转位图

我一直在寻找解决这个问题的一天,但没有任何帮助,甚至这里的答案.文档也没有解释任何内容.

我只是想在另一个物体的方向上进行旋转.问题是位图不是围绕固定点旋转,而是围绕位图(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().有人可以帮助并推动我朝着正确的方向前进吗?:)

android center bitmap matrix image-rotation

83
推荐指数
5
解决办法
13万
查看次数

标签 统计

android ×1

bitmap ×1

center ×1

image-rotation ×1

matrix ×1