标签:pen 网络图 content etc exception ring tor 方法 factory
注意:该方法必须要在子线程中调用,因为涉及网络请求
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; }
标签:pen 网络图 content etc exception ring tor 方法 factory
原文地址:http://www.cnblogs.com/zhujiabin/p/6778355.html