[英]Saving Image on Parse.com
我想將圖像上傳到parse.com。 我從圖庫中選擇圖像,並將其放在活動A的ImageView中,如下所示:
addImage.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
};
然后,在OnActivityforResult中:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
mMediaUri = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(mMediaUri,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
// ImageView imageView = (ImageView) findViewById(R.id.imgView);
propertyImage.setImageBitmap(BitmapFactory.decodeFile(picturePath));
Bitmap bmp = BitmapFactory.decodeFile(picturePath);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byteArray = stream.toByteArray();
}
然后,我通過Intent發送字節數組:
intent.putExtra("Image",byteArray);
現在處於活動B:
byte[] data = getIntent().getByteArrayExtra("Image");
final ParseFile file = new ParseFile("propic.png", data);
file.saveInBackground();
最后,我將其發送為解析:
listedProperty.put("PropPic", file);
從那時起,數據就沒有進入我的解析類,並且我從解析中獲得了失敗的回調。 有什么事嗎
logcat的:
03-14 04:14:23.987 1688-1688/com.iwillcode.realestate I/Choreographer﹕ Skipped 33 frames! The application may be doing too much work on its main thread.
03-14 04:14:25.808 1688-1717/com.iwillcode.realestate W/EGL_emulation﹕ eglSurfaceAttrib not implemented
03-14 04:14:25.808 1688-1717/com.iwillcode.realestate W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa24751e0, error=EGL_SUCCESS
03-14 04:14:34.204 1688-1717/com.iwillcode.realestate W/EGL_emulation﹕ eglSurfaceAttrib not implemented
03-14 04:14:34.204 1688-1717/com.iwillcode.realestate W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa2426fc0, error=EGL_SUCCESS
03-14 04:14:35.624 1688-1717/com.iwillcode.realestate W/EGL_emulation﹕ eglSurfaceAttrib not implemented
03-14 04:14:35.624 1688-1717/com.iwillcode.realestate W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa2475a20, error=EGL_SUCCESS
03-14 04:14:37.224 1688-1717/com.iwillcode.realestate W/EGL_emulation﹕ eglSurfaceAttrib not implemented
03-14 04:14:37.224 1688-1717/com.iwillcode.realestate W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa2b0b140, error=EGL_SUCCESS
03-14 04:14:39.432 1688-1717/com.iwillcode.realestate W/EGL_emulation﹕ eglSurfaceAttrib not implemented
03-14 04:14:39.432 1688-1717/com.iwillcode.realestate W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa2426060, error=EGL_SUCCESS
03-14 04:14:46.229 1688-1717/com.iwillcode.realestate W/EGL_emulation﹕ eglSurfaceAttrib not implemented
03-14 04:14:46.229 1688-1717/com.iwillcode.realestate W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa2475e20, error=EGL_SUCCESS
03-14 04:14:51.681 1688-1717/com.iwillcode.realestate W/EGL_emulation﹕ eglSurfaceAttrib not implemented
03-14 04:14:51.681 1688-1717/com.iwillcode.realestate W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa2b18f20, error=EGL_SUCCESS
03-14 04:14:53.801 1688-1717/com.iwillcode.realestate W/EGL_emulation﹕ eglSurfaceAttrib not implemented
03-14 04:14:53.801 1688-1717/com.iwillcode.realestate W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xacf8fde0, error=EGL_SUCCESS
03-14 04:14:55.425 1688-1717/com.iwillcode.realestate W/EGL_emulation﹕ eglSurfaceAttrib not implemented
03-14 04:14:55.425 1688-1717/com.iwillcode.realestate W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa0f727e0, error=EGL_SUCCESS
03-14 04:15:03.226 1688-1688/com.iwillcode.realestate E/No﹕ Unseccessfull
不確定是否有幫助,但是我保存了位圖圖像以進行解析,這是在使用相機拍照后進行的。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
byte[] image_byte_array;
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
post_object = new Post();
Bundle extras = data.getExtras();
image = (Bitmap) extras.get("data");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.PNG, 100, stream);
image_byte_array = stream.toByteArray();
picture_file = new ParseFile("Picture", image_byte_array);
picture_file.saveInBackground();
post_object.put("Image", picture_file);
post_object.saveInBackground();
}
}
我在proyect中有一個類似的代碼,並以此將用戶的圖像保存在Parse上並在ParseImageView中顯示,並且它可以正常工作:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(
selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
yourSelectedImage.compress(Bitmap.CompressFormat.PNG, 100, stream);
// put on my imageview
// ImagenParseUserNavigation.setImageBitmap(yourSelectedImage);
// ImagenParseUser.setImageBitmap(yourSelectedImage);
byte[] image = stream.toByteArray();
ParseUser currentUser = ParseUser.getCurrentUser();
ParseFile photoFile = new ParseFile("fotoperfil"+currentUser.getUsername()+".png",image);
currentUser.put("Imagen", photoFile);
currentUser.saveInBackground();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.