dam*_*ian 2 android matrix android-canvas
我需要一些矩阵运算方面的帮助。我想要实现的是:
我的代码目前如下所示:
Matrix matrix = new Matrix();
matrix.preRotate(mShip.getRotation(), mShip.getX() + mShip.getCurrentBitmap().getWidth()/2f, mShip.getY() + mShip.getCurrentBitmap().getHeight()/2f);
matrix.setScale((1.0f * mShip.getWidth() / mShip.getCurrentBitmap().getWidth()), (1.0f * mShip.getHeight() / mShip.getCurrentBitmap().getHeight()));
matrix.postTranslate(mShip.getX(), mShip.getY());
mCanvas.drawBitmap(mShip.getCurrentBitmap(), matrix, mBasicPaint);
Run Code Online (Sandbox Code Playgroud)
但是旋转的中心错误,我不知道如何解决这个问题 - 我已经环顾四周,但只发现了类似的问题,没有解决方案。我认为我可能必须将其中一个操作应用于另一个操作的值,因为它们是按顺序执行的,但我不知道如何操作。
试试这个代码:
Matrix matrix = new Matrix();
matrix.setTranslate(-mShip.getCurrentBitmap().getWidth()/2f, -mShip.getCurrentBitmap().getHeight()/2f);
matrix.postRotate(mShip.getRotation());
matrix.postTranslate(mShip.getX(), mShip.getY());
matrix.postScale((1.0f * mShip.getWidth() / mShip.getCurrentBitmap().getWidth()), (1.0f * mShip.getHeight() / mShip.getCurrentBitmap().getHeight()), mShip.getX(), mShip.getY());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8121 次 |
| 最近记录: |