Android通过URL加载网络图片

  public static Bitmap getBitmap(String path) throws IOException {

        URL url = new URL(path);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setConnectTimeout(5000);
        conn.setRequestMethod("GET");
        if (conn.getResponseCode() == 200){
            InputStream inputStream = conn.getInputStream();
            Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
            return bitmap;
        }
        return null;
    }

最后直接ImageView.setImageBitmap(bitmap);

posted @ 2016-08-25 16:27  newcaoguo  阅读(12729)  评论(0编辑  收藏  举报