2012-11-19 96 views
0

從互聯網下載圖像時出現問題。 問題是圖像正在彼此下載。 程序在android < = 2.2上運行時出現問題。 下載約50幅圖像,分辨率320×200使用android <= 2.2下載圖像

的代碼片段:

public class DownloadOfferImages extends AsyncTask<List<ImageOfferData>, Bitmap, Void> { 

    private InputStream inputStream; 
    private BufferedInputStream buffer; 

    @Override 
    protected Void doInBackground(List<ImageOfferData>... offer) { 
     for(int i = 0 ; !isInteruppted() && i < offer[0].size() ; i++) { 
      if(offer[0].get(i).getImage() == null) 
       downloadImage(offer[0].get(i)); 
     } 
     return null; 
    } 

    private void downloadImage(ImageOfferData offerData) { 
     try { 
      download(offerData); 
     } catch (MalformedURLException e) { 
      e.printStackTrace(); 
     } catch (OutOfMemoryError e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } finally { 
      try { 
       closeStreams(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

    private void download(ImageOfferData offerData) throws MalformedURLException, OutOfMemoryError, IOException { 
     URL imageUrl = new URL(offerData.getImageURL()); 
     URLConnection connection = imageUrl.openConnection(); 
     inputStream = connection.getInputStream(); 
     buffer = new BufferedInputStream(inputStream); 
     Bitmap image = BitmapFactory.decodeStream(buffer); 
     buffer.close(); 
     offerData.setImage(image); 
     publishProgress(image); 
    } 

    /* 
    * [rest of code] 
    * 
    * 
    * */ 

} 
+0

這是什麼問題? –

+0

問題是圖像每秒下載一次。 – wilek

回答