Saving Images To Parse
I am trying to have the users upload their image (profile picture) into parse as part of their profile creation page where they would have to fill out various information. Users wo
Solution 1:
you forgot to save the file first
ParseFilefile=newParseFile("profilePicture.png", image);
file.saveinBackground()
Solution 2:
You can define a new class called util.java and in that class you would write a method
publicstaticbyte[] getbytearray(Bitmap bm){
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
return byteArray;
}
Now you don't need to these basic lines again and again. And more important thing you should use asynctask to avoid out of memory error like -
publicclassstoreimageextendsAsyncTask<Bitmap,Void,Void>{
@Overrideprotected Void doInBackground(Bitmap... params) {
byte[] byteArray = util.getbytearray(params[0]);
ParseUseruser= ParseUser.getCurrentUser();
ParseFileparseFile=newParseFile(user.getUsername()+"dp.png",byteArray);
parseFile.saveInBackground();
user.put("dp", parseFile);
user.saveInBackground();
Log.d("mayank","asynctask successful");
// Bitmap dpbitmap2 = ((BitmapDrawable)imageView.getDrawable()).getBitmap();//ByteArrayOutputStream stream2 = new ByteArrayOutputStream();// dpbitmap.compress(Bitmap.CompressFormat.PNG, 0, stream2);// byte[] byteArray2 = stream2.toByteArray();// ParseFile parseFile2 = new ParseFile(user.getUsername()+"dp_circle.png",byteArray2);// ParseObject dp = new ParseObject("dp");// dp.put("pic",byteArray2);// dp.pinInBackground();returnnull;
}
}
after this you should write
new storeimage().execute(BitmapFactory.decodeFile(picturePath));
Post a Comment for "Saving Images To Parse"