阅读971 返回首页    go 技术社区[云栖]


BitmapFactory.decodeFile能否对一张来自HTTP的图片进行解码呢

 BitmapFactory.decodeFile(String)没有从网络解码图片的能力。不过还有另外一个函数可以帮到你——BitmapFactory.decodeStream(InputStream)函数,具体实现请参考以下代码:
 
01 // 准备一张网络图片,例如:[img]https://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);

最后更新:2017-04-02 06:51:46

  上一篇:go Action Bar使用方法 - Android活动栏(一)
  下一篇:go android.resource://这个Uri你知道吗