简体   繁体   English

在Parse.com上保存图像

[英]Saving Image on Parse.com

I want to upload an Image to parse.com. 我想将图像上传到parse.com。 I choose the Image from gallery and place it in an ImageView in Activity A as follows: 我从图库中选择图像,并将其放在活动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);
}
};

Then, In OnActivityforResult: 然后,在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();

        }

Then I send the byte array through Intent: 然后,我通过Intent发送字节数组:

intent.putExtra("Image",byteArray); 

Now in Activity B: 现在处于活动B:

byte[] data = getIntent().getByteArrayExtra("Image");


        final ParseFile file = new ParseFile("propic.png", data);
        file.saveInBackground();

Finally I send it to parse like: 最后,我将其发送为解析:

listedProperty.put("PropPic", file);

Since then, data is not getting into my parse class and I am getting an unsuccessful callback from parse. 从那时起,数据就没有进入我的解析类,并且我从解析中获得了失败的回调。 What could be wrong? 有什么事吗

LogCat: 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

Not sure if this helps but I save my bitmapped images to parse like this, this is after taking the photo with the camera. 不确定是否有帮助,但是我保存了位图图像以进行解析,这是在使用相机拍照后进行的。

@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();
    }
}

i have a similar code in my proyect, and i save the image of an user on Parse with this and show in a ParseImageView, and it work: 我在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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM