通过图片的url下载图片并解析为Bitmap:
URL url =new URL(imgurl);
URLConnection urlconn = url.openConnection();
urlconn.connect();
HttpURLConnection httpconn =(HttpURLConnection)urlconn;
HttpResult = httpconn.getResponseCode();
System.out.println(HttpResult);
if(HttpResult != HttpURLConnection.HTTP_OK){
}
else {
int filesize = urlconn.getContentLength();
Log.d(TAG,"Image size = "+String.valueOf(filesize));
Bitmap bmp = BitmapFactory.decodeStream(urlconn.getInputStream());
return bmp;
}
}catch (IOException e){
Log.d(TAG,"failed to read image");
}