如何在android中显示外部图像?
答
有很多方法可以实现您的请求。基本上你必须用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();
后,你获得你可以用它在你的ImageView例如
答
只是另一种方法的位图对象从URL下载图像
try {
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL("http://abc.com/image.jpg").getContent());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}