Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am working on a parse.com Android application, in which I am putting my predefined/default image in ParseFile and sending it to the server. Now I want to put an image on user selection from gallery.

My code is given below:

//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());
        }
    }
});
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
242 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try this...

 public void setImage( Bitmap map){


    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    // Compress image to lower quality scale 1 - 100
    map.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    byte[] image = stream.toByteArray();

    // Create the ParseFile
    ParseFile file  = new ParseFile("picture_1.jpeg", image);
     // Upload the image into Parse Cloud
    ParseUser user = ParseUser.getCurrentUser();
    user.put("profilePic",file);

user.saveInBackground(new SaveCallback() {
    @Override
    public void done(ParseException e) {

    }
});

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...