【发布时间】:2014-11-26 10:25:50
【问题描述】:
我正在开发一个 parse.com Android 应用程序,其中我将我的预定义/默认图像放入 ParseFile 并将其发送到服务器。现在我想在图库中的用户选择上放一张图片。
我的代码如下:
//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());
}
}
});
【问题讨论】:
标签: android image bitmap parse-platform