【Android開發】URL[] 轉成 bitmap[]
阿新 • • 發佈:2018-12-27
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; }