如何在Parse中加载图像

时间:2015-10-09 11:39:26

标签: android parse-platform

我在解析时有一个班级photo,在我的项目中有4个imageView

enter image description here

所以我想从photo加载图片并将其设置为imageviews trade_id。 告诉我,我该怎么做!

2 个答案:

答案 0 :(得分:1)

@kishore jethava   is also right but you can also get url from parse then load that url into imageview with the help of any library like Glide or Picassio or even you can download the image manually from the provided url.

ParseQuery<ParseObject> queryPhoto = ParseQuery.getQuery("photo");
        queryPhoto.whereEqualTo("trade_id",trade_id);
        queryPhoto.findInBackground(new FindCallback<ParseObject>() {
            @Override
            public void done(List<ParseObject> listPhoto, ParseException e) {
                // TODO Auto-generated method stub
                if(e == null){
                    for (ParseObject photo : listPhoto){
                         ParseFile parseFile = photo.getParseFile("imageFile");
                         if(parseFile!=null)
                         {
                          final String imageULr=parseFile.getUrl();
                         Glide.with(context).load(imageULr).into(imageView);
                         }
                         }
                     }
                }
            }
        });

答案 1 :(得分:0)

这样做

ParseQuery<ParseObject> queryPhoto = ParseQuery.getQuery("photo");
    queryPhoto.whereEqualTo("trade_id",trade_id);
    queryPhoto.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> listPhoto, ParseException e) {
            // TODO Auto-generated method stub
            if(e == null){
                for (ParseObject photo : listPhoto){
                     ParseFile parseFile = (ParseFile)photo.get("imageFile");
                     final String imageName =photo.getString("imageName");
                     if (parseFile != null) {
                            parseFile.getDataInBackground(new GetDataCallback() {

                                @Override
                                public void done(byte[] data, ParseException e) {
                                    // TODO Auto-generated method stub
                                    if (data != null && e == null) {
                                            Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0,data.length);
                                            if(imageName.equals("image1"))
                                                    imageVIew1.setImageBitmap(bitmap);
                                                else if(imageName.equals("image2"))
                                                    imageVIew2.setImageBitmap(bitmap);
                                                else if(imageName.equals("image3"))
                                                    imageVIew3.setImageBitmap(bitmap);
                                                else if(imageName.equals("image4"))
                                                    imageVIew4.setImageBitmap(bitmap);                                      }
                                }
                            });
                        }
                 }
            }
        }
    });