我想显示外部图像,例如:
"http://abc.com/image.jpg"
在我的 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();
获得 Bitmap 对象后,您可以在 ImageView 上使用它
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)