通过url联网获取图片并解析
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;
}声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇:没有了
