答案 0 :(得分:6)
有很多方法可以实现您的请求。基本上你必须使用urlrequest下载图像,然后使用InputStream创建一个Bitmap对象。
只是示例代码:
URL url = new URL("http://asd.jpg");
URLConnection conn = url.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
Bitmap bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
获取Bitmap对象后,您可以在ImageView上使用它,例如
答案 1 :(得分:3)
另一种从网址下载图片的方法
try {
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL("http://abc.com/image.jpg").getContent());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}