简体   繁体   中英

Android : load an imageview from a Parsefile

I'm trying to find a ParseObject by " objectId ", then retrieve the image " ImageFile " and then Load it to the imageview, it doesn't work and i'm getting the USER String, can you help me out with this, it works when i use another query like : query.find()

      ParseImageView mealImage = (ParseImageView) findViewById(R.id.icon);

    ParseQuery<ParseObject> query1 = ParseQuery.getQuery("Annonces");


    query1.getInBackground("ux3Af0cwEx", new GetCallback<ParseObject>() {
      public void done(ParseObject Annonces, ParseException e) {


             photoFile = (ParseFile) Annonces.get("ImageFile");
             text1.setText((CharSequence) Annonces.get("USER"));

      }
    });
    mealImage.setParseFile(photoFile);
    mealImage.loadInBackground(new GetDataCallback() {
        @Override
        public void done(byte[] data, ParseException e) {

        }
    });

    }

The code for displaying image in imageview:

ParseFile image = (ParseFile) userData.getParseFile("user_image");

then call following function.

loadImages( photoFile, mealImage);

private void loadImages(ParseFile thumbnail, final ImageView img) {

    if (thumbnail != null) {
        thumbnail.getDataInBackground(new GetDataCallback() {
            @Override
            public void done(byte[] data, ParseException e) {
                if (e == null) {
                    Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
                    img.setImageBitmap(bmp);
                } else {
                }
            }
        });
    } else {
        img.setImageResource(R.drawable.menu);  
    }
}// load image

If you are using Picasso or Glide for image loading and don't want to change the image loading logic, you can extract image url from ParseFile and load it in background. Like:

ParseFile thumbnail = parseObject.getParseFile("image");
if(thumbnail != null) {
    String imageUrl = thumbnail.getUrl();
    Picasso.with(mContext).load(imageUrl).into(imageView);
}

No need to load thumbnail ParseFile data separately.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM