public static Bitmap getResponsebitmap(String urlPath) {
URL url;
Bitmap map = null;
try {
// 创建url对象
url = new URL(urlPath);
// 通过url获取对象
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// 设置连接超时
conn.setConnectTimeout(10 * 1000);
// 设置请求方式
conn.setRequestMethod("GET");
// 连接
conn.connect();
if (conn.getResponseCode() == 200) {
InputStream inputStream = conn.getInputStream();
map = BitmapFactory.decodeStream(inputStream);
inputStream.close();
}
} catch (MalformedURLException e) {
Log.e("ur-->", "URL不正确");
} catch (IOException e) {
e.printStackTrace();
}
return map;
}
通过url联网获取图片并解析
最新推荐文章于 2024-07-13 03:15:58 发布