user991429
user991429

Reputation: 322

canvas image rotation on with center like dialer

I have a square shape image which having circle view, I am drawing that image in center of circle using canvas using below code:

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

I want to rotate this image like a dialer relative to center.Facing issue to make rotation of Image around that circle center.

Used code for rotation:

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

Help will be appreciated.

Thanks

Upvotes: 0

Views: 276

Answers (1)

Douglas Jones
Douglas Jones

Reputation: 2542

I think you're going to want to rotate the canvas:

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

Upvotes: 1

Related Questions