Reputation: 2718
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?
Upvotes: 2
Views: 2322
Reputation: 98
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.
Upvotes: 1
Reputation: 2541
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
Upvotes: 0