android 怎么把网络图片生成一个Bitmap显示在ImageView中

 

public static Bitmap getImage(String Url) throws Exception {
  try {
   URL url = new URL(Url);
   String responseCode = url.openConnection().getHeaderField(0);
   if (responseCode.indexOf("200") < 0)
    throw new Exception("图片文件不存在或路径错误,错误代码:" + responseCode);

   return BitmapFactory.decodeStream(url.openStream());
  } catch (IOException e) {
   // TODO Auto-generated catch block
   throw new Exception(e.getMessage());
  }
 }

//要显示的图片

setImageViewResource(getImage(URL))

你可能感兴趣的:(android,exception,网络,String,url)