android如何获取url指定的图片资源
16lz
2021-01-23
// 获取指定路径的图片
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 ImageView图片显示点击背景切换
- Android中图片占用内存的计算
- Android imageView图片按比例缩放(转)
- android中九宫图整齐排列(图片处理)
- Android studio实现左右滑动切换图片
- Android-给图片添加暗影
- Java和Android Http连接程序:使用java.net.URL 下载服务器图片到