设置位图的旋转和位置

Set the rotation and position of bitmap

我想知道如何既可以更改位图的位置又可以旋转它。我在 canvas.

画画

我目前正在使用这行代码:

canvas.drawBitmap(bitmap, posX, posY, paint);

而且我认为使用矩阵进行旋转是最佳选择?问题是上面发布的代码行不采用矩阵而是采用位置。

还有一行类似的代码:

canvas.drawBitmap(bitmap, matrix, paint);

这个需要一个矩阵而不是一个位置。

我应该怎么做?

矩阵变换可以同时包含位置和旋转(以及其他内容)。使用像 postTranslate() 这样的方法来修改矩阵,而不是像 setTranslate() 这样的方法,它在添加新的转换之前重置矩阵。