我想从一些网址从网络获取图像,并显示在我的ImageView。下面是我使用的代码:
Bitmap bm = null;
try {
URL aURL = new URL("stringURL");
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
}catch (Exception e) {
// TODO: handle exception
}
iv.setImageBitmap(bm);
但我无法得到图像
2条答案
按热度按时间wsewodh21#
我认为错误在于
应该不带引号
如果stringURL是有效的URL,它将工作...
希望对你有帮助…
ia2d9nvy2#
我认为你可以更好地使用下面的代码,这对我来说非常好。