我正在使用此方法来检索位图
private Bitmap getBitmap(String url)
{
File f=fileCache.getFile(url);
//from SD cache
if(b!=null)
return b;
//from web
try {
Bitmap bitmap=null;
Log.e("URL", url);
URL imageUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
conn.setConnectTimeout(30000);
conn.setReadTimeout(30000);
InputStream is=conn.getInputStream();
OutputStream os = new FileOutputStream(f);
Utils.CopyStream(is, os);
os.close();
return bitmap;
} catch (Exception ex){
ex.printStackTrace();
return null;
}
}
正如您在上面看到的,我如何从 SD 卡或缓存以及从 Web 代码获取的位图进行解码?我尝试过一种方法,但没有成功。
最佳答案
关于java - 如何从缓存文件和网络中解码位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7656274/