我正在尝试全屏显示图像,但图像质量似乎下降了。我从 URL 获取图像,下载它,当我显示图像时,它看起来很糟糕。我得到的图像是高分辨率的,所以我不知道问题出在哪里?
这是我显示图像的布局:
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/full_screen_banner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/app_name" />
这是java代码:
imageViews.put(imageView, url);
Bitmap bitmap = memoryCache.get(url);
if (bitmap != null)
imageView.setImageBitmap(bitmap);
最佳答案
如果您正在使用图像加载器,只需转到 imageloader
类即可
检查这些行
private Bitmap decodeFile(File f) {
try {
// decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FileInputStream(f), null, o);
// Find the correct scale value. It should be the power of 2.
final int REQUIRED_SIZE = 100;
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 1;
while (true) {
if (width_tmp / 2 < REQUIRED_SIZE
|| height_tmp / 2 < REQUIRED_SIZE)
break;
width_tmp /= 2;
height_tmp /= 2;
scale *= 2;
}
// decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
} catch (FileNotFoundException e) {
}
return null;
}
关于android - 全屏显示图像 - 失去质量安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17849642/