1

rotate image on canvas around its center . i tried some example from net but i am failed

if i am using bitmap.creatbitmap with matrix i am getting error

Please suggest me which is better

Thanks in advance

Aswan

Andro Selva
  • 53,136
  • 52
  • 190
  • 238
Aswan
  • 4,947
  • 10
  • 44
  • 67

1 Answers1

7

You can use a matrix to rotate. First you set the position (I'm using the coordinates of the bitmap's centre). Then apply a rotation. Then draw using your matrix.

    Matrix transform = new Matrix();
    transform.setTranslate(xOfCentre, yOfCentre);
    transform.preRotate(turnDegrees, width/2, height/2);
    canvas.drawBitmap(bitmap, transform, null);

If you want your turning to be animated, then see my answer to "animating and rotating an image...".

Community
  • 1
  • 1
idbrii
  • 10,113
  • 5
  • 57
  • 100