0

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

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);

我想像相对于中心的拨号器一样旋转此图像。面临的问题是围绕该圆心旋转图像。

用于旋转的代码:

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);

帮助将不胜感激。

谢谢

4

1 回答 1

1

我想你会想要旋转画布:

canvas.save();
canvas.rotate(angle, rotationCenterX, rotationCenterY);
// draw here
canvas.restore();
于 2013-08-14T14:48:14.750 回答