当前位置: 首页 > 知识库问答 >
问题:

在Android的ParseFile中从图库中放置图像

姬乐池
2023-03-14

我正在做解析。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());
        }
    }
});

共有1个答案

桑成荫
2023-03-14

试试这个…

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

    }
});

}
 类似资料:
  • null 那个代码有什么问题?我不明白为什么不能将ImageRi发送到ImageView。我还验证了我正在传递给setImageURI函数的Uri值是正确的。

  • 问题内容: 我已经将图像内的边框设置为none。我现在想将该图像放在其包含div的中心。我曾尝试使用,但没有用。 我敢肯定,我忽略了一些愚蠢的事情,但是我想得到stackoverflow社区的帮助,所以这并不需要我花一个小时盯着屏幕来弄清楚。非常感谢。 这是CSS … 问题答案: 尝试将图片的属性设置为:

  • 我已经成功地使用Parse将声音片段上传到设备或从设备下载。我也在尝试类似的事情,但有图像。我有一个imageView,它包含用户选择的图像。我想将此图像作为嵌套在parseObject(称为“profileParseObject”)中的parseFile发送 我看到了这篇文章:将图库中的图像放入 ParseFile android 但是,使用: 导致“当前上下文中不存在名称”位图“”(我不知道需

  • 我写了一个代码,在选项卡式窗格中显示图像。我的代码如下所示 好吧,然后我需要在图像的特定位置放置一个标记…如何在上面放置标记…? 任何关于在图像中放置标记的帮助都是受欢迎的....

  • 我正在尝试做一个小应用程序,只显示图片从一个特定的文件夹在一个图库视图。我找到了几个例子,但每一个都只能显示一个图像。我将在下面发布的这个例子是一个很好的帮助,它做几乎完全是我想要它做的,我只需要改变它显示图像从特定的文件夹,而不是所有的文件夹。我花了几天的时间来尝试,但我似乎没有添加正确的代码。我觉得这是一件很简单的事情,我也错过了。如有任何帮助,我们将不胜感激!