【问题标题】:Putting image from gallery in ParseFile in Android将图库中的图像放入 Android 中的 ParseFile
【发布时间】:2014-11-26 10:25:50
【问题描述】:

我正在开发一个 parse.com Android 应用程序,其中我将我的预定义/默认图像放入 ParseFile 并将其发送到服务器。现在我想在图库中的用户选择上放一张图片。

我的代码如下:

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

【问题讨论】:

    标签: android image bitmap parse-platform


    【解决方案1】:

    试试这个...

     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) {
    
        }
    });
    
    }
    

    【讨论】:

      猜你喜欢
      • 2016-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多