我正在尝试使用运动传感器旋转图像等应用程序....我的问题是图像不能正确地围绕中心旋转....而且我的角度范围是0到90和0到-90 .. 以下是我的代码.....
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
Bitmap arrow = BitmapFactory.decodeResource(getResources(),R.drawable.arrow);
int arrowW = arrow.getWidth();
int arrowH = arrow.getHeight();
float scaleWidth = 1;
float scaleHeight = 1;
int centrex = arrowW/2;
int centrey = arrowH/2;
int X=108;
int Y=100;
int angle=0;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
matrix.postRotate(angle, X+centrex , Y+centrey );
Bitmap resizedBitmap = Bitmap.createBitmap(arrow, 0, 0, arrow.getWidth(), arrow.getHeight(), matrix, true);
canvas.save();
canvas.drawBitmap(resizedBitmap, X, Y, null);
invalidate();
}
我从onCreate方法获取角度值.....使用方向传感器(滚动值).. 但是当我旋转屏幕时,我的图像正在旋转但不完全围绕图像中心..
答案 0 :(得分:0)
旋转不应该与X和Y有关:
matrix.postRotate(angle,centrex,centrey);