从parse中检索图像文件 - android

时间:2014-06-18 14:39:18

标签: android parse-platform

我正在尝试检索我从应用上传的图片:

intent = getIntent();
    String id = intent.getStringExtra("id");
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Items");
    query.getInBackground(id, new GetCallback<ParseObject>()
    {
        @Override
        public void done(ParseObject object, ParseException e)
        {
            if (e == null)
            {
                setTitle(object.getString("name"));
                textPlatform.setText(object.getString("platform"));
                textPrice.setText(String.valueOf(object.getDouble("price")));
                textDelivery.setText(String.valueOf(object.getDouble("delivery")));
                textLocation.setText(object.getString("location"));
                textCondition.setText(object.getString("condition"));
                textSeller.setText(object.getString("seller"));
                ParseFile applicantResume = (ParseFile) object.get("image");
                applicantResume.getDataInBackground(new GetDataCallback()
                {
                    public void done(byte[] data, ParseException e)
                    {
                        if (e == null)
                        {
                            Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
                            imgItem.setImageBitmap(bmp);
                        }
                        else
                        {
                            e.printStackTrace();
                        }
                    }
                });
            } else
            {
                e.printStackTrace();
            }
        }

    });

我可以成功检索其他项目而不是文件(我知道存在并位于列#34;图像&#34;)。

先谢谢你了

2 个答案:

答案 0 :(得分:12)

这就是我这样做的方式: 我使用getParseFile方法从解析中获取文件:

ParseFile postImage = object.getParseFile(ParseConstants.PARSE_KEY_FILE);
String imageUrl = postImage.getUrl() ;//live url 
Uri imageUri = Uri.parse(imageUrl);

然后我使用Picasso来显示图像:

Picasso.with(context).load(imageUri.toString()).into(mPostImage);

答案 1 :(得分:4)

by this you can display the image....   

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

//call the function 

displayImage(image, image_expert);

//这里是函数

    private void displayImage(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);

                        if (bmp != null) {

                            Log.e("parse file ok", " null");
                            // img.setImageBitmap(Bitmap.createScaledBitmap(bmp,
                            // (display.getWidth() / 5),
                            // (display.getWidth() /50), false));
                            img.setImageBitmap(getRoundedCornerBitmap(bmp, 10));
                            // img.setPadding(10, 10, 0, 0);



                        }
                    } else {
                        Log.e("paser after downloade", " null");
                    }

                }
            });
        } else {

            Log.e("parse file", " null");

            // img.setImageResource(R.drawable.ic_launcher);

            img.setPadding(10, 10, 10, 10);
        }

    }