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,910
  • 52
  • 193
  • 240
Aswan
  • 5,085
  • 10
  • 46
  • 70

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,975
  • 5
  • 66
  • 107