2013-06-19 48 views
0

我試圖從urls下載一些圖像,但是我一直爲它嘗試下載的每個圖像都收到解碼錯誤。這是我想要將下載的圖像添加到類數組中的代碼。從URL下載圖像時解碼錯誤

for(int i=0;i<jArray.length();i++){ 

       json_data = jArray.getJSONObject(i); 
       Programme Progresult = new Programme(); 

       Progresult.name = json_data.getString("name"); 
       Progresult.event = json_data.getString("event"); 
       Progresult.price = json_data.getString("price"); 


       String imageurl = json_data.getString("preview"); 
       Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(imageurl).getContent()); 
       Progresult.progpreview = bitmap; 


       arraydata.add(Progresult); 

       } 
      } 
      catch(JSONException e1){ 

       } 
      catch (ParseException e1) { 
       e1.printStackTrace(); 
       } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      return arraydata; 
       } 

這裏是我收到的每個圖像日誌貓錯誤.....

06-19 13:44:26.550: D/skia(722): --- decoder->decode returned false 

這裏是一個圖片的網址,我試圖下載

http://ec2-54-228-87-185.eu-west-1.compute.amazonaws.com/corkgaa/Matchprogrammes/sample3.bmp 

回答

0

試試這個--->

URL url = new URL(imageurl); 
    HttpURLConnection conn = (HttpURLConnection)url.openConnection(); 
    conn.setConnectTimeout(30000); 
    conn.setReadTimeout(30000); 
    conn.setInstanceFollowRedirects(true); 
    InputStream is=conn.getInputStream(); 
    Bitmap bitmap = BitmapFactory.decodeStream(is); 
    is.close(); 
    conn.disconnect(); 
+0

我仍然得到同樣的解碼錯誤 –

+0

通過這個[鏈接](http://stackoverflow.com/questions/4339082/android-decoder-decode-returned-false-for-bitmap-download) –

+0

謝謝,我會嘗試其中一些 –