How to rotate a bitmap in android at a center point using a matrix

I use the matrix to rotate the image, it works, but I have a problem with the new bitmap. The new bitmap has some space, although I installed a support element. What should I do to rotate the image, but I do not want space. I use this code below to rotate a bitmap:

Bitmap bitmapOrg = BitmapFactory.decodeResource (getResources (), R.drawable.sticker01); int width = bitmapOrg.getWidth (); int height = bitmapOrg.getHeight ();

Matrix matrix = new matrix (); matrix.postRotate (rotation, width / 2, height / 2);

Bitmap resizedBitmap = Bitmap.createBitmap (bitmapOrg, 0, 0, width, height, matrix, true); BitmapDrawable bmd = new BitmapDrawable (resizedBitmap);

imageView.setBackgroundColor (Color.white); imageView.setImageDrawable (BMD); imageView.setScaleType (ScaleType.FIT_XY);

imageView -> width and height = WRAP_CONTENT

Rotate 0 degrees: enter image description here

10 degree rotation: enter image description here It has a space around the real image.

50 degree rotation: enter image description here It has a space around the real image (even larger space).

+4
source share
2 answers

Zoom in. Image type:

imageView.setScaleType(ScaleType.CENTER); 
0
source

Use a rotation matrix with an average value

matrix.postScale (scale, scale, mid.x, mid.y);

0
source

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


All Articles