0
我得到了这个小功能,它允许我从path
加载一个图像,名为name
。它的工作原理是,我必须多次呼叫这个问题,而不是昙花一现。比方说,在特定活动的负载下十几次。它需要几秒钟来加载它们。Android:not optimal图片加载
它是最佳的吗?有一种更轻松的方式来达到相同的结果吗?
public static Bitmap loadImageFrom(File path, String name)
{
try {
File f = new File(path, name);
return BitmapFactory.decodeStream(new FileInputStream(f));
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
}
}
我尝试添加if(!f.exists()) return null;
这样的:
public static Bitmap loadImageFrom(File path, String name)
{
try {
File f = new File(path, name);
if(!f.exists()) return null;
return BitmapFactory.decodeStream(new FileInputStream(f));
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
}
}
我知道那是多余的,但我不能删除尝试catch子句,因为它给了我一个错误,如果我这样做。但是,没有加速注意到。
有什么建议吗?