我需要从我的服务器下载图像并将该图像加载到 imageview 中。所以我有一个问题 - 我可以将图像下载到内存中并将其设置为 ImageView,而不保存在 sdcard/本地存储上吗?或者我必须下载到某个文件存储中?如果可能的话请给我例子。
最佳答案
同样的问题也被问到了,所以你可以搜索一下,
InputStream in = null;
try
{
URL url = new URL("URL FOR IMAGE");
URLConnection urlConn = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) urlConn;
httpConn.connect();
in = httpConn.getInputStream();
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
bmpimg = BitmapFactory.decodeStream(in);
ImageView iv = "MY IMAGEVIEW";
iv.setImageBitmap(bmimg);
关于java - 如何在 Java、Android 中下载 ImageView 的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7807144/