我正在尝试从网址下载一些图片,但我不断为其尝试下载的每个图片收到解码错误。这是我的代码,我想将下载的图像添加到类数组中。
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;
}
以下是我为每张图片获取的日志cat错误.....
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 :(得分:0)
试试这个---&gt;
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();