I'm setting an ImageView
to a file downloaded from a remote server then saved to the device's local storage. For some reason, the image is getting distorted. From my research, if I set the scaleType
, adjustViewBounds
, maxWidth
and maxHeight
properties of the ImageView
, then Android will scale the image for me. That seems strange because in my other, non-Android developing, I've always had to resize the image programmatically first before displaying it. However, this post says Android will do it.
This is the image I'm trying to display: Image
Distorted image:
Code:
<ImageView
android:id="@+id/title_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="60dp"
android:maxHeight="60dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
/>
String path = getExternalStorageDirectory() + "/MyApp/Images";
String fileName = "Test.jpg";
File imageFile = new File(path, fileName);
if (imageFile.exists())
{
Uri imageUri = Uri.fromFile(imageFile);
((ImageView)findViewById(R.id.title_image)).setImageURI(thumbnail);
}