-1

我想从表 1 中获取图像以在解析时更新表 2 中的图像这是我的代码

 ParseFile image= ParseUser.getCurrentUser().getParseFile("image");

    if(image==null)
    {

    }
    else
    {
        try {
            byte[] data=image.getData();


            Bitmap bmp = BitmapFactory
                  .decodeByteArray(
                          data, 0,
                          data.length);


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




        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

这段代码运行完美,它可以正确检索和设置图像现在我希望这个“图像”上传到我的第二个表中我正在这样做

ParseQuery<ParseObject> query = ParseQuery.getQuery("XYZ");
          String user_id=ParseUser.getCurrentUser().getObjectId();
        query.getInBackground(user_id, new GetCallback<ParseObject>() {

            @Override
            public void done(ParseObject pdata, ParseException e) {
                // TODO Auto-generated method stub

                pdata.put("image",image); // this line throw NullPointerException
                pdata.saveInBackground();
            }
        });

我做错了什么请帮助?

4

1 回答 1

0

你需要 ParseFile 对象。试试下面的代码。(它工作正常,我刚刚检查过)

               byte[] pfArray = getBytesFromBitmap(bmp);
                ParseFile file = new ParseFile("abc.png", pfArray);
                // Upload the image into Parse Cloud
                file.saveInBackground(new SaveCallback() {

                    @Override
                    public void done(ParseException e) {
                        System.out.println("saved");

                    }
                });

public byte[] getBytesFromBitmap(Bitmap bitmap) {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(CompressFormat.PNG, 70, stream);
        return stream.toByteArray();
    }

希望能帮助到你。

于 2014-11-17T12:02:54.383 回答