【发布时间】:2013-07-18 12:12:34
【问题描述】:
大家好!
我有一个小问题但是一个问题!
我在 2 个活动之间传输最多 6 张照片。但是 2 之间的加载非常长(6-10 秒)。
我的代码:
String[] toShare = getIntent().getStringArrayExtra("toShare");
for (int i = 0; i < toShare.length; i++) {
if(toShare[i] != null){
LesPlus.get(i).setImageBitmap(genereThumb(toShare[i]));
}else{
LesPlus.get(i).setImageDrawable(getResources().getDrawable(R.drawable.btnadd));
}
}
基因拇指:
File file = new File(path);
FileInputStream fs=null;
Bitmap bm = null;
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int largeurEcran = dm.widthPixels;
int LargeurCol = (int) ((largeurEcran / 3) - 15);
BitmapFactory.Options bfOptions=new BitmapFactory.Options();
bfOptions.inDither=false;
bfOptions.inPurgeable=true;
bfOptions.inInputShareable=true;
bfOptions.inTempStorage=new byte[32 * 1024];
try {
fs = new FileInputStream(file);
} catch (FileNotFoundException e) {
System.out.println(e);
}
try {
if(fs!=null) bm=BitmapFactory.decodeFileDescriptor(fs.getFD(), null, bfOptions);
} catch (IOException e) {
e.printStackTrace();
} finally{
if(fs!=null) {
try {
fs.close();
} catch (IOException e) {
System.out.println(e);
}
}
}
return Bitmap.createScaledBitmap(bm, LargeurCol, LargeurCol, true);
}
如果有帮助的话,我会开发 Galaxy S2 :D。谢谢你的回答
【问题讨论】:
-
要管理位图,建议使用硬缓存。看看github.com/nostra13/Android-Universal-Image-Loader 这是迄今为止我所知道的最好的库来管理下载,redim;缓存和显示图像
-
谢谢,但我没有找到任何关于缩略图的信息 :( 我想使用默认的 android 库
-
我试过了,但它什么也没显示,而且 .writeDebugLogs() 不起作用!它需要一个演员:(
-
你说的是通用图片加载器吗?
-
还有一点,你在位图上的工作不应该在主线程上;)