Reputation: 211
I would like to display an image from external storage which is 72x72 px. My device has high density. The image view height and width are "wrap_content".
I got different results if I load the image or use an URL.
If I use an URL like this then the result will be about 48x48px.
imageView.setImageURI(Uri.fromFile(file));
If I load the bitmap the result is 72x72 px as expected:
InputStream is = context.getContentResolver().openInputStream(Uri.fromFile(file));
Bitmap b = BitmapFactory.decodeStream(is, null, null);
is.close();
iv2.setImageBitmap(b);
You can see the results here:
It would be better if I could use the setImageURI
and not to preload
the image and I would like to display the image in appwidgets too.
Can you tell me what cause the difference and how can I avoid it?
Upvotes: 1
Views: 685
Reputation: 7605
try by this i think it work either change in xml file in imageview by
android:scaleType="centerCrop"
android:adjustViewBounds="true"
or either use in java code
image.setAdjustViewBounds(true);
image.setScaleType(ScaleType.CENTER_CROP);
either use "centercrop" or "fitxy" may it also works
Upvotes: 1
Reputation: 685
If both images have different sizes and you can't change the image size you have to set in your xml the image width and height to for example 72dp. You shouldn't use px, but dp because otherwise it wouldn't display good on different phones.
Upvotes: 0