How to update image using parse Android?

感情迁移 提交于 2019-12-13 07:58:18

问题


I want to fetch image from table 1 to update image in table 2 on parse here is my code

 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();
        }

This code is working perfect it retrieves and set image properly now I want this "image" to upload in my Second table I am doing this

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();
            }
        });

What I am doing wrong anyone please help?


回答1:


You need ParseFile object. Try the following code. (It works fine, I just checked it)

               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();
    }

hope it helps.



来源:https://stackoverflow.com/questions/26971250/how-to-update-image-using-parse-android

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