Ros*_*hni 1 android image bitmap bitmapfactory
我使用https://github.com/thest1/LazyList进行图像缓存.我必须全屏显示图像.但是图像质量有很大的损失.哪个代码我必须改变以获得原始image.thanks提前.
在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=70;
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;
}
Run Code Online (Sandbox Code Playgroud)
并从此方法中删除以下行,
while(true){
if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE)
break;
width_tmp/=2;
height_tmp/=2;
scale*=2;
}
Run Code Online (Sandbox Code Playgroud)
这将确保您的图像根本不会缩放.
但是你必须记住,如果你这样做,你的应用程序很容易受到OOM的攻击.
| 归档时间: |
|
| 查看次数: |
1190 次 |
| 最近记录: |