我正在尝试使用运动传感器旋转图像之类的应用程序....我的问题是图像无法正确围绕中心旋转....我的角度范围是 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 方法获取角度值.....使用方向传感器(滚动值)..但是当我旋转屏幕时,我的图像正在旋转但不完全围绕图像中心旋转..