Rotate the bitmap at a fixed point, like a clock in SurfaceView

I have an image in my drawablewatch folder . I want to rotate it at a fixed point, like a clock. I tried below code that rotates a hand in a circular path around a fixed point, but not like a clock.

 Matrix matrix = new Matrix();
 matrix.reset();
 matrix.preTranslate(0, 0);
 matrix.postRotate(angleRotation, -0, -0);
 matrix.postTranslate(240, 480);

 canvas.drawColor(Color.WHITE);
 canvas.drawBitmap(bitmap, matrix, null);

I struggle for hours to figure it out. Any help would be appreciated.

I also tried links to links for reference without success.

+4
source share
2 answers

. px py - canvas. bitmap.getWidth()/2 - . x cordinate. y cordinate 10. angleRotation - , .

So matrix.postTranslate(-bitmap.getWidth()/2, -10); - .

.

        Matrix matrix = new Matrix();
        matrix.reset();
        Paint paint = new Paint();
        float px = 240;
        float py = 480;
        matrix.postTranslate(-bitmap.getWidth()/2, -10);
        matrix.postRotate(angleRotation);
        matrix.postTranslate(px, py);
        canvas.drawBitmap(bitmap, matrix, paint);

. , .

+2

, .

 private Bitmap rotateImage(Bitmap src,int degrees) {
         Matrix matrix = new Matrix();
         matrix.postRotate(degrees);
        return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
}
0

Source: https://habr.com/ru/post/1628817/


All Articles