public Bitmap getWebBitmap(String imgUrl) {
        Bitmap bitmap =null;
        try {
            InputStream inputStream = null;
            URL url;
            url = new URL(imgUrl);
            if (url != null) {
                // 打开连接
                HttpURLConnection httpURLConnection = (HttpURLConnection) url
                        .openConnection();
                httpURLConnection.setConnectTimeout(3000);// 设置网络连接超时的时间为3秒
                httpURLConnection.setDoInput(true); // 打开输入流
                int responseCode = httpURLConnection.getResponseCode(); // 获取服务器响应值
                if (responseCode == HttpURLConnection.HTTP_OK) { // 正常连接
                    inputStream = httpURLConnection.getInputStream(); // 获取输入流
                }
                bitmap = BitmapFactory.decodeStream(inputStream);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bitmap;
    }

最好得到了Bitmap就可随便使用了。

需要注意的是,但凡要联网的:1、都要设置访问权;2、放到线程中去处理

<uses-permission android:name="android.permission.INTERNET"/>

 

相关文章:

  • 2021-11-07
  • 2021-09-17
  • 2022-12-23
  • 2021-08-25
  • 2021-09-26
  • 2021-06-26
  • 2022-12-23
猜你喜欢
  • 2021-10-21
  • 2021-07-24
  • 2021-07-15
  • 2021-07-09
  • 2021-08-27
相关资源
相似解决方案