Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotating an image around a pivot point

Tags:

android

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.

like image 237
Gratzi Avatar asked Dec 13 '11 13:12

Gratzi


People also ask

Is it possible to rotate object about any pivot point?

We can generate rotation about any given point other than the origin. This is Pivot Point Rotation. For 2D rotation, we must have an angle of rotation, the point about which rotation is performed. We must also know the direction of rotation.

How do I rotate a picture in Excel?

Click the object that you want to rotate. Under Drawing Tools (or Picture Tools if you're rotating a picture), on the Format tab, in the Arrange group, click Rotate, and then: To rotate the object 90 degrees to the right, click Rotate Right 90°. To rotate the object 90 degrees to the left, click Rotate Left 90°.

How do I rotate an image at custom angles?

Manually rotate a picture or shape Select the picture or shape. Manually rotate the text box by selecting the shape or picture rotation handle and dragging in the direction you want. To keep the rotation to 15 degree angles, press and hold Shift while you drag the rotation handle.


1 Answers

I think you should try doing this:

imageView.setPivotX(desiredXPivotPoint);
imageView.setPivotY(desiredYPivotPoint);

That should do the trick.

like image 152
JMRboosties Avatar answered Oct 04 '22 21:10

JMRboosties