【Android开发】URL[] 转成 bitmap[]

public static Bitmap[] getBitmapFromURL(String[] path) throws MalformedURLException {

        Bitmap[] b = new Bitmap[path.length];

        for (int i = 0; i < path.length; i++) {
            URL url = new URL(path[i]);
            HttpURLConnection conn = null;
            try {
                conn = (HttpURLConnection)url.openConnection();
                conn.setConnectTimeout(5000);
                conn.setRequestMethod("GET");
                if(conn.getResponseCode() == 200){
                    InputStream inputStream = conn.getInputStream();
                    Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
                    b[i]=bitmap;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return b;
    }
posted @ 2018-12-27 14:47  浪里小白龙呼呼呼  阅读(1036)  评论(0编辑  收藏  举报