Jui*_*icy 7 android bitmap matrix draw
我一直在查看文档,并且唯一drawBitmap()允许Matrixas参数不通过参数采用任何类型的屏幕坐标.
我正在使用以下代码绘制矩阵旋转的位图:
Matrix matrix = new Matrix();
matrix.setRotate(rotation,bitmap.getWidth()/2,bitmap.getHeight()/2);
canvas.drawBitmap(bitmap, matrix, null);
Run Code Online (Sandbox Code Playgroud)
这当然是我的位图0,0.如何设置位置并使用矩阵?
理想情况下,我想使用目标Rect:
this.destRect = new Rect(
x - spriteWidth / 2,
y - spriteHeight / 2,
x + spriteWidth / 2,
y + spriteHeight /2
);
Run Code Online (Sandbox Code Playgroud)
编辑:
以下建议在评论中我试过这个:
Matrix matrix = new Matrix();
matrix.setTranslate(x, y);
matrix.setRotate(rotation,bitmap.getWidth()/2,bitmap.getHeight()/2);
canvas.drawBitmap(bitmap, matrix, null);
Run Code Online (Sandbox Code Playgroud)
但无济于事.仍然绘制了位图0,0
EDIT2:
以下是使用矩阵在自身上旋转图像然后将其放在以下位置的技巧x,y:
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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3737 次 |
| 最近记录: |