Set rotation and position of bitmap

最后都变了- 提交于 2019-12-07 20:43:24

问题


I would like to know how i both can change the position of a bitmap and at the same time rotate it. Im drawing at a canvas.

Im currently using this line of code:

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

and I think using a matrix for rotation is the best option? The problem is that the line of code, posted above, doesn't take a matrix but a position.

There is also a similar line of code:

canvas.drawBitmap(bitmap, matrix, paint);

This one takes a matrix but not a position.

How should I do this?


回答1:


Matrix matrix = new Matrix();
matrix.SetRotate(90,pivotX,pivotY);
matrix.PostTranslate(positionX,positionY);
canvas.drawBitmap(bitmap, matrix , null);

In words - set the position after rotating.




回答2:


Take the position into a matrix as posMatrix and multiply it with rotation matrix. Then pass the resultant matrix as the parameter.

Edit ---

Matrix myTransformedMatrix = new Matrix();
myTransformedMatrix.setRotate(<rotation in dergrees>);
myTransformedMatrix.setTranslate(<translation in points>);

canvas.drawBitmap(bitmap, myTransformedMatrix, paint);

for more info on matrix class go to http://developer.android.com/reference/android/graphics/Matrix.html



来源:https://stackoverflow.com/questions/13110796/set-rotation-and-position-of-bitmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!