我試圖從圖像的路徑獲取位圖圖像。但BitmapFactory.decodeStream
返回null
值。Android:bitmapfactory.decodestream返回null
代碼:
URL url = new URL(path);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
connection.disconnect();
input.close();
我已搜查在更多的網站,我仍然沒有得到解決。
你確定該URL指向的東西,BitmapFacotry可以解碼? – Blackbelt
是,網址:http://static.adzerk.net/Advertisers/12f0cc69cd9742faa9c8ee0f7b0d210e.jpg – Ponmalar
有一個bug BitmapFactory.decodeStream()。比如decodeStream,請嘗試將圖像保存在sd上,然後通過BitmpaFoctory加載它,或者從代碼中讀取:http://android-developers.blogspot.it/2010/07/multithreading-for-performance.html – Blackbelt