画布图像旋转与中心像拨号器

时间:2013-08-14 14:14:13

标签: android android-canvas sensor

我有一个有圆形视图的方形图像,我使用下面的代码使用画布在圆心绘制该图像:

Bitmap bitmapCompass = BitmapFactory.decodeResource(getResources(), R.drawable.compass_rim);
  float w2= (w-bitmapCompass.getWidth())/2;
  float h2= (h-bitmapCompass.getHeight())/2;

  canvas.drawBitmap(bitmapCompass, w2, h2, paint);

我想将此图像像拨号器相对于center.Facing问题旋转,以使图像围绕该圆心旋转。

用于轮换的代码:

Bitmap bitmapCompass = BitmapFactory.decodeResource(getResources(), R.drawable.compass_back);
  float w2= (w-bitmapCompass.getWidth())/2;
  float h2= (h-bitmapCompass.getHeight())/2;
  Matrix matbitmapCompass = new Matrix();
     matbitmapCompass.postRotate((float)90);
     Bitmap bmpRotateCompass = Bitmap.createBitmap(bitmapCompass, 0,0, bitmapCompass.getWidth(), bitmapCompass.getHeight(), matbitmapCompass, true);
  canvas.drawBitmap(bmpRotateCompass, w2, h2, paint);

帮助将不胜感激。

由于

1 个答案:

答案 0 :(得分:1)

我想你想要旋转画布:

canvas.save();
canvas.rotate(angle, rotationCenterX, rotationCenterY);
// draw here
canvas.restore();