我想将图像上传到 parse.com。我从图库中选择图像并将其放置在 Activity 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);
现在进行 Activity B:
byte[] data = getIntent().getByteArrayExtra("Image");
final ParseFile file = new ParseFile("propic.png", data);
file.saveInBackground();
最后我将其发送给解析:
listedProperty.put("PropPic", file);
从那时起,数据就不再进入我的解析类,并且我从解析中得到不成功的回调。可能出了什么问题?
日志猫:
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();
}
}
关于java - 在 Parse.com 上保存图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29045487/