在Android中的ParseFile中将图库中的图像放入 [英] Putting image from gallery in ParseFile in Android
本文介绍了在Android中的ParseFile中将图库中的图像放入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个parse.com Android应用程序,我将预定义/默认图像放在ParseFile中并将其发送到服务器。现在我想在图库中为用户选择添加图像。
I am working on a parse.com Android application, in which I am putting my predefined/default image in ParseFile and sending it to the server. Now I want to put an image on user selection from gallery.
我的代码如下:
//It is my default image which i am getting from drawable.
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.usman);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] image = stream.toByteArray();
ParseFile file = new ParseFile("profileImage.png", image);
// Upload the image into Parse Cloud
file.saveInBackground();
// Create a column named "profileImage" and insert the image
Constants.user.put("profileImage", file);
Constants.user.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
// dismissLoadingDialog();
if (e == null) {
Toast.makeText(getApplicationContext(),"User Profile Has Been Updated!",Toast.LENGTH_SHORT).show();
} else {
Logs.e(getClass().getName(), e.toString());
Toast.makeText(getApplicationContext(), "Exception/n" + e, Toast.LENGTH_SHORT).show();
// showMessage(e.getMessage());
}
}
});
推荐答案
试试这个......
Try this...
public void setImage( Bitmap map){
ByteArrayOutputStream stream = new ByteArrayOutputStream();
// Compress image to lower quality scale 1 - 100
map.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] image = stream.toByteArray();
// Create the ParseFile
ParseFile file = new ParseFile("picture_1.jpeg", image);
// Upload the image into Parse Cloud
ParseUser user = ParseUser.getCurrentUser();
user.put("profilePic",file);
user.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
}
});
}
这篇关于在Android中的ParseFile中将图库中的图像放入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文