4
votes

I use matrix to rotate my image, it's working but i have some problem with new image bitmap. The new bitmap have some space even though I have set the pivot. What should i do to rotate the image but i don't want the space. I use this code below to rotate the bitmap:

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

Matrix matrix = new Matrix(); matrix.postRotate(rotate, 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 & height = WRAP_CONTENT

Rotate 0 degree: enter image description here

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

Rotate 50 degree: enter image description here It has space around the real image (even bigger space)..

2
hi dear you get your ans or notAnkitkumar Makwana

2 Answers

0
votes

Change the imageview scaleType:

imageView.setScaleType(ScaleType.CENTER);
0
votes

Use matrix post rotate with mid value

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