通过url联网获取图片并解析

来源:互联网 发布:在centos上安装apache 编辑:程序博客网 时间:2024/04/27 14:05
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;}

0 0