我試圖從遠程服務器下載圖像,下載的圖像數量爲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;
}
您是否得到相同的錯誤? – pradeep 2011-03-18 04:16:39
我試過同樣的錯誤仍然存在 – pradeep 2011-03-18 04:39:01
請抓住那些圖像下載鏈接並在瀏覽器中測試...可能是一些鏈接被破壞... – 2011-03-18 05:56:57