简体   繁体   中英

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM