问题
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