0

我正在尝试从 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
4

1 回答 1

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();
于 2013-06-19T14:19:55.640 回答