網絡圖片轉換成Bitmap

 public static Bitmap netImgToBitmap(String url) {
         URL mUrl = null;
         Bitmap bitmap = null;
         try {
             mUrl = new URL(url);
         } catch (MalformedURLException e) {
             e.printStackTrace();
         }
         try {
             HttpURLConnection conn = (HttpURLConnection) mUrl.openConnection();
             conn.setDoInput(true);
             conn.connect();
             InputStream inputStream = conn.getInputStream();
             bitmap = BitmapFactory.decodeStream(inputStream);
             inputStream.close();
         } catch (IOException e) {
             e.printStackTrace();
         }
         return bitmap;
     }



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章