Android : load an imageview from a Parsefile

最后都变了- 提交于 2019-12-04 18:14:45
param

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!