Rotating Image on A canvas in android

前端 未结 6 1153
心在旅途
心在旅途 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:25

    Based on @Sakthi 's code, but add scaling :)

            Rect rect = new Rect(0,0,canvas.getWidth(), canvas.getHeight());
            Matrix matrix = new Matrix();
            matrix.postTranslate(-bitmap.getWidth()/2, -bitmap.getHeight()/2);
            matrix.postScale(
                    ((float)rect.width()) / bitmap.getWidth(),
                    ((float)rect.height()) / bitmap.getHeight());
            matrix.postRotate(180);
            matrix.postTranslate(rect.exactCenterX(), rect.exactCenterY());
            canvas.drawBitmap(bitmap, matrix, null);
    

提交回复
热议问题