b.i
b.i

Reputation: 1107

How to prevent an image from being resized in Android

I am writing an application on android. I am downloading an image from the server and trying to set it as an ImageView background using setBackgroundDrawable.

Drawable drawable = Drawable.createFromPath(path)
imageView.setBackgroundDrawable(drawable);

It works but the image is resized (it is getting smaller). Does anyone have an idea about how to set an image view background without changing its size?

Edit: I solved the problem by using:

File imgFile = new File(path);
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
imageView.setImageBitmap(myBitmap);

Upvotes: 3

Views: 2548

Answers (2)

Sadeshkumar Periyasamy
Sadeshkumar Periyasamy

Reputation: 4908

Use these two properties:

 android:scaleType
 android:adjustViewBounds

Study about them in : ImageView

Upvotes: 1

Mitul Nakum
Mitul Nakum

Reputation: 5584

imageView.setScaleType (ImageView.ScaleType.MATRIX)

Set image scale type to Matrix it will scale using the image matrix when drawing.

Upvotes: 2

Related Questions