2011-03-18 26 views
1

我試圖從遠程服務器下載圖像,下載的圖像數量爲30個。我用來下載圖像的代碼是下面。一些圖像下載成功,一些圖像不下載並引發上述異常。可能是什麼問題。Android:從遠程服務器下載圖像時出現此錯誤:SkImageDecoder :: Factory返回null

public static Bitmap loadBitmap(String url) 
{ 
    Bitmap bitmap = null; 
    InputStream in = null; 
    BufferedOutputStream out = null; 

    try { 
     in = new BufferedInputStream(new URL(url).openStream(), 4*1024); 

     final ByteArrayOutputStream dataStream = new ByteArrayOutputStream(); 
     out = new BufferedOutputStream(dataStream, 4 * 1024); 

     int byte_; 
     while ((byte_ = in.read()) != -1) 
      out.write(byte_); 
     out.flush(); 

     final byte[] data = dataStream.toByteArray(); 
     BitmapFactory.Options options = new BitmapFactory.Options(); 
     //options.inSampleSize = 1; 

     bitmap = BitmapFactory.decodeByteArray(data, 0, data.length,options); 
    } catch (IOException e) { 
     Log.e("","Could not load Bitmap from: " + url); 
    } finally { 
     try{ 
      in.close(); 
      out.close(); 
     }catch(IOException e) 
     { 
      System.out.println(e); 
     } 
    } 

    return bitmap; 
} 

回答

0

在我來說,我解決了這個錯誤有編碼的URL 因爲,我想下載圖像URL具有波斯字母(或其他的Unicode字符) 因此,我用編碼的UTF-8字母替換了所有波斯語字符

相關問題