Android 网络图片Url 转 Bitmap

五陵年少金市东,银鞍白马渡春风。这篇文章主要讲述Android 网络图片Url 转 Bitmap相关的知识,希望能为你提供帮助。
注意:该方法必须要在子线程中调用,因为涉及网络请求

public Bitmap getBitmap(String url) { Bitmap bm = null; try { URL iconUrl = new URL(url); URLConnection conn = iconUrl.openConnection(); HttpURLConnection http = (HttpURLConnection) conn; int length = http.getContentLength(); conn.connect(); // 获得图像的字符流 InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is, length); bm = BitmapFactory.decodeStream(bis); bis.close(); is.close(); // 关闭流 } catch (Exception e) { e.printStackTrace(); } return bm; }

【Android 网络图片Url 转 Bitmap】 

    推荐阅读