[英]Rotating an image around a pivot point
The issue is simple: I want to rotate an image around a certain pivot point. 问题很简单:我想围绕某个枢轴点旋转图像。 Here is the code I use: 这是我使用的代码:
Matrix matrix = new Matrix();
matrix.setTranslate(bmpWidth/2, 0);
matrix.preRotate(degrees, bmpWidth/2, 0);
Bitmap resizedBitmap = Bitmap.createBitmap(
bitmap, 0, 0, bmpWidth, bmpHeight, matrix, true);
ImageView imageView = (ImageView) findViewById(R.id.bell);
imageView.setImageBitmap(resizedBitmap);
I get the rotation degrees from the accelerometer sensor. 我从加速计传感器获得旋转度。 The result is that every time the image is rotated around its center point. 结果是每次图像围绕其中心点旋转。
I think you should try doing this: 我想你应该尝试这样做:
imageView.setPivotX(desiredXPivotPoint);
imageView.setPivotY(desiredYPivotPoint);
That should do the trick. 这应该够了吧。
这有点旧,但有一个功能允许您指定旋转度和枢轴点:
imageView.setRotation(degrees, px, py)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.