Rotating Image on A canvas in android

前端 未结 6 1151
心在旅途
心在旅途 2020-11-27 13:33

I want to Rotate Image according to a specific angle in android ,some thing like a compass...

I have this code...it works on drawPath() but i want to replace the pat

6条回答
  •  一向
    一向 (楼主)
    2020-11-27 14:09

    You can either rotate your bitmap when you draw it by using a matrix:

    Matrix matrix = new Matrix();
    matrix.setRotate(angle, imageCenterX, imageCenterY);
    yourCanvas.drawBitmap(yourBitmap, matrix, null);
    

    You can also do it by rotating the canvas before drawing:

    yourCanvas.save(Canvas.MATRIX_SAVE_FLAG); //Saving the canvas and later restoring it so only this image will be rotated.
    yourCanvas.rotate(-angle);
    yourCanvas.drawBitmap(yourBitmap, left, top, null);
    yourCanvas.restore();
    

    Pick the one that suits you the best.

提交回复
热议问题