- public Bitmap getBitmap(String url) {
- Bitmap bm =null;
- try {
- URL iconUrl =new URL(url);
- URLConnection conn = iconUrl.openConnection();
- HttpURLConnection http = (HttpURLConnection) conn;
- intlength = http.getContentLength();
- conn.connect();
- // 获得图像的字符流InputStreamis= conn.getInputStream();
- BufferedInputStream bis =newBufferedInputStream(is, length);
- bm = BitmapFactory.decodeStream(bis);
- bis.close();
- is.close();// 关闭流
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- return bm;
- }
来源: http://www.bubuko.com/infodetail-2044168.html