drawBitmap:如何设置坐标并使用矩阵?

时间:2014-11-18 21:44:13

标签: android matrix bitmap draw

我已经looking at the documentationdrawBitmap()唯一允许Matrix作为参数的Matrix matrix = new Matrix(); matrix.setRotate(rotation,bitmap.getWidth()/2,bitmap.getHeight()/2); canvas.drawBitmap(bitmap, matrix, null); 并未通过参数获取任何类型的屏幕坐标。

我使用以下代码通过矩阵旋转绘制我的位图:

0,0

当然,我在this.destRect = new Rect( x - spriteWidth / 2, y - spriteHeight / 2, x + spriteWidth / 2, y + spriteHeight /2 ); 处绘制了我的位图。如何设置位置并使用矩阵?

理想情况下,我想使用目标Rect:

    Matrix matrix = new Matrix();
    matrix.setTranslate(x, y);
    matrix.setRotate(rotation,bitmap.getWidth()/2,bitmap.getHeight()/2);
    canvas.drawBitmap(bitmap, matrix, null);

编辑:

在评论中提示我尝试了这个:

0,0

但无济于事。位图仍在x,y

处绘制

EDIT2:

以下是使用矩阵在自身上旋转图像然后将其放在 Matrix matrix = new Matrix(); matrix.reset(); matrix.postTranslate(-bitmap.getWidth() / 2, -bitmap.getHeight() / 2); // Centers image matrix.postRotate(rotation); matrix.postTranslate(x, y); canvas.drawBitmap(bitmap, matrix, null); 处的技巧:

{{1}}

0 个答案:

没有答案
相关问题