android如何获取url指定的图片资源

// 获取指定路径的图片
public static Bitmap getImage(String urlpath)
throws Exception {
URL url = new URL(urlpath);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5 * 1000);
Bitmap bitmap = null;
if (conn.getResponseCode() == 200) {
InputStream inputStream = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(inputStream);
}
return bitmap;
}

你可能感兴趣的:(Android,android,url,图片,Bitmap)