BitmapFactory.decodeFile(String)没有从网络解码图片的能力。不过还有另外一个函数可以帮到你——BitmapFactory.decodeStream(InputStream)函数,具体实现请参考以下代码:
01 | // 准备一张网络图片,例如:[img]http://www.example.com/img.jpg[/img] |
02 | URL aryURI = new URL(String); |
03 | // 取得连接 |
04 | URLConntection conn = aryURI.openConnection(); |
05 | conn.connect(); |
06 | // 获取流 |
07 | InputStream is = conn.getInputStream(); |
08 | // 将图像留转换成实体Bitmap对象 |
09 | Bitmap bm = BitmapFactory.decodeStream(is); //关键所在 |
10 | // 关闭连接 |
11 | is.close(); |
12 | imageView.setImageBitmap(bm); |