android - 从解析到 ImageView 加载图像

标签 android parse-platform

我将 ParseFile 加载到数组列表照片中。 但现在我想在 ImageView 中显示它?

ArrayList<Photo> photos = new ArrayList<>();
    try {
        ParseQuery<ParseObject> query = new ParseQuery<>("photo");
        query.setLimit(2000);
        List<ParseObject> listA = query.find();
        for (ParseObject mPhoto : listA) {
            Photo newPhoto = new Photo();
            newPhoto.setImage((ParseFile) mPhoto.get("imageFile"));
            newPhoto.setTrade_id((String) mPhoto.get("trade_id"));
            photos.add(newPhoto);
        }
    } catch (com.parse.ParseException e) {
        Log.e("Error", e.getMessage());
        e.printStackTrace();
    }

我该怎么做?

最佳答案

试试这个代码。这将向您展示如何为 1 个 ParseFile 显示 1 个图像。如果您想显示arraylist中的所有图像,您应该将Bitmap对象保存到arraylist而不是ParseFile对象

 ParseFile fileObject = (ParseFile) object
    .get("imageFile");
fileObject
    .getDataInBackground(new GetDataCallback() {

        public void done(byte[] data,
            ParseException e) {
            if (e == null) {
                // Decode the Byte[] into
                // Bitmap
                Bitmap bmp = BitmapFactory
                    .decodeByteArray(
                        data, 0,
                        data.length);

                // initialize
                ImageView image = (ImageView) findViewById(R.id.image);

                // Set the Bitmap into the
                // ImageView
                image.setImageBitmap(bmp);

            } else {
                Log.d("test",
                    "Problem load image the data.");
            }
        }
    });

另一种方法是您需要获取图像的 url
String imageUrl = parseFileObject.getUrl();

然后使用 PicassoUniversalImageLoader用于加载图像

注意:您应该使用 AsyncTask使用 Parse 提高性能和同步

希望这有帮助

关于android - 从解析到 ImageView 加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32901767/

相关文章:

node.js - 如何在 Heroku 上的 Nodejs 应用程序中使用 "underscore"模块?

javascript - 当我在 Parse 中使用事件时,在使用事件调用触发器后,不会执行监听器回调

Android 自定义 CalendarView 事件颜色

javascript - 某些 Android 设备/Chrome 上的 HTML5 数字输入中没有小数位

Android数据绑定(bind)产生 "Source folders generated at wrong location"

ios - PFFacebookUtils登录后台无法将值转换为PFUserResultBlock

java - 即使所有参数都准确,仍获取 'ParseException: invalid login parameters'

android - 当客户端调用 WorkManager.initialize() 时,WorkManager 在库中不起作用

java - Android-Java HTTPCLIENT 通过 Content-Disposition 图片上传发送 http 参数

Swift & Parse - 空 PFFile