AndiM
AndiM

Reputation: 2188

Rotate Image without losing resolution

I am having problem while rotating an Image Bitmap.When I rotate Image it lose its resolution.I want to rotate image everytime when user click on Button.Code on button's click is here:

matrix.postRotate(90);

bitmap = Bitmap.createBitmap(bitmap_rotate, 0, 0, bitmap_rotate.getwidth(),bitmap_rotate.getHeight(),matrix, true);
d_reflect = new BitmapDrawable(bitmap);

image_view.removeAllViews();
image_view.setBackgroundDrawable(d_reflect);

Where image_view is LinearLayout and I want to set rotate LinearLayout.It lose its resolution everytime I rotate image.My original bitmap size is 300x300.I have googled a lot to find solution but none of them worked for me. Any solution will be appreciated.Thanks in advance..

Upvotes: 0

Views: 575

Answers (2)

SceLus
SceLus

Reputation: 1107

Create a scaled bitmap with the desired width and height:

Bitmap bmp = Bitmap.createScaledBitmap(bitmap_rotate, 300, 300, false);

Upvotes: 0

Pratik
Pratik

Reputation: 30855

Here is the code for rotating an image smoothly inside an imageview without creating an extra Bitmap.

Matrix m = new Matrix();
m.setRotate(degrees);
image_view.setImageMatrix(m);

Upvotes: 1

Related Questions