保存图像解析 [英] Saving images to Parse

查看:124
本文介绍了保存图像解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有用户上传自己的形象(资料图片)成解析它们的配置文件创建页面的一部分,在那里他们将要填写各种信息。用户将能够preVIEW它们在图像视图中的图片。

I am trying to have the users upload their image (profile picture) into parse as part of their profile creation page where they would have to fill out various information. Users would be able to preview their picture in an image view.

我曾尝试通过以下步骤来实现这一点。

I have tried to achieve this by taking the following steps.

1)创建一个按钮,允许用户从他们的画廊检索图片,并上传到创建的ImageView的。

1) Creating a button that would allow users to retrieve a picture from their gallery, and to upload it into the ImageView created.

Button buttonLoadImage = (Button) findViewById(R.id.btnPictureSelect);
        buttonLoadImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent i = new Intent(
                        Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(i, RESULT_LOAD_IMAGE);
            }
        });
@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) {
                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 picturePath = cursor.getString(columnIndex);
                cursor.close();

                ImageView imageView = (ImageView) findViewById(R.id.profilePicturePreview);
                imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));

            }

        }
        } 

这部分已普遍执行的成功与用户能够从他们自己的相册上传图片,并看到它直观地显示在图像视图。

This part has generally been executed with success with users being able to upload image from their gallery and seeing it visually displayed in the image view.

2)存储用户的解析上传的图片 这是我奋力的区域。评论已被添加在之间的code作进一步澄清,并强调是我的问题是。

2) Storing user uploaded images on parse This is the area where I am struggling at. Comments have been added in between the code for further clarification, and to highlight were my questions are.

 ParseUser currentUser = ParseUser.getCurrentUser();

                 /* This is the section where the images is converted, saved, and uploaded. I have not been able Locate the image from the ImageView, where the user uploads the picture to imageview from either their gallery and later on from facebook */ 
                Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
                        /*to be retrieved from image view */);
                // Convert it to byte
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                // Compress image to lower quality scale 1 - 100
                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                byte[] image = stream.toByteArray();

                // Create the ParseFile
                ParseFile file = new ParseFile("profilePicture.png", image);
                // Upload the image into Parse Cloud


                // Create a column named "Profile Picture" and set the string
                currentUser.put("ImageName", "Profile Picture");

                // Create a column named "ImageFile" and insert the image
                currentUser.put("ProfilePicture", file);

                // Create the class and the columns

                currentUser.put("name", name); 
                currentUser.put("age", age); 
                currentUser.put("headline", headline); 
                currentUser.saveInBackground(new SaveCallback() {
                    @Override
                    public void done(ParseException e) {
                        setProgressBarIndeterminateVisibility(false);

                        if (e == null) {
                            // Success!
                            Intent intent = new Intent(ProfileCreation.this, MoodActivity.class);
                            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            startActivity(intent);
                        }
                        else {
                            AlertDialog.Builder builder = new AlertDialog.Builder(ProfileCreation.this);
                            builder.setMessage(e.getMessage())
                                .setTitle(R.string.signup_error_title)
                                .setPositiveButton(android.R.string.ok, null);
                            AlertDialog dialog = builder.create();
                            dialog.show();
                        }
                    }
                });
            }
        }
    });

如果你能反正帮助我,这将是真正有帮助的。 如果你需要进一步澄清,让我知道。 先谢谢了。

If you could assist me in anyway, it would be truly helpful. If you require further clarification, let me know. Thanks in advance.

推荐答案

您忘了先保存文件

ParseFile file = new ParseFile("profilePicture.png", image);
file.saveinBackground()

这篇关于保存图像解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆