Android的 - 围绕中心点旋转图像?中心点、图像、Android

2023-09-12 02:28:22 作者:野性沾了眉丶

我如何可以旋转的位图(而不是视图或帆布)围绕其中心点当用户触摸并拖动它?

我曾尝试对堆栈溢出的例子负载,没有出现一起工作。

到目前为止,我有:

 双R = Math.atan2(POSX  -  dial.getWidth()/ 2,dial.getHeight()/ 2  - 波西);
旋转=(int)的Math.toDegrees(r)的;
 

解决方案

创建矩阵则设置为通过的 setRotate(度) 。然后使用创建新的位图时,这个矩阵: Bitmap.createBitmap(..)

How can I rotate a bitmap (not a view or canvas) around its center point when the user touches it and drags it?

ai中如何围绕中心点旋转复制

I have tried loads of examples on stack overflow and none appear to work.

So far I have:

double r = Math.atan2(posX - dial.getWidth() / 2, dial.getHeight() / 2 - posY);
rotation = (int) Math.toDegrees(r);

解决方案

Create Matrix then set rotate via setRotate(degrees). Then use this matrix when creating new Bitmap: Bitmap.createBitmap(..)