网络图片url转为bitmap

来源:互联网 发布:tomcat gzip js css 编辑:程序博客网 时间:2024/06/05 16:44
private Bitmap decodeUriAsBitmapFromNet(String url) {
   URL fileUrl = null;
   Bitmap bitmap = null;

   try {
      fileUrl = new URL(url);
   } catch (MalformedURLException e) {
      e.printStackTrace();
   }

   try {
      HttpURLConnection conn = (HttpURLConnection) fileUrl
            .openConnection();
      conn.setDoInput(true);
      conn.connect();
      InputStream is = conn.getInputStream();
      bitmap = BitmapFactory.decodeStream(is);

      is.close();
   } catch (IOException e) {
      e.printStackTrace();
   }
   return bitmap;

}
原创粉丝点击