当前位置: 动力学知识库 > 问答 > 编程问答 >

android - Rotate an image around center

问题描述:

How can I rotate an image around it's center point? This rotates it but also moves it:

 Matrix mat = new Matrix();

mat.postRotate(45);

Bitmap bMapRotate = Bitmap.createBitmap(dialBM, 0, 0, dialBM.getWidth(),dialBM.getHeight(), mat, true);

dial.setImageBitmap(bMapRotate);

I've checked other examples on this site, but they either fail to work or use canvas, I do not wish to use canvas.

网友答案:

The second and third arguments to postRotate is the x and y pivot point.

 mat.postRotate(45, dialBM.getWidth()/2, dialBM.getHeight()/2);
网友答案:

Probably because your matrix rotates around (0,0), and not the middle of your bitmap. You should declare two additional matrices - one for moving the bitmap's center to (0,0) (shift by -getWidth()/2, -getHeight(2)) and one to move the bitmap's center back to (0,0). Multiply the three matrices, and then the result.

分享给朋友:
您可能感兴趣的文章:
随机阅读: