【问题标题】:How to get the actual size of image on ActivityResult() in android如何在android中获取图像onActivityResult()的实际大小
【发布时间】:2020-03-04 13:19:27
【问题描述】:

下面是我的代码。单击 imageview 相机将打开,我们将捕获图像。在下面的 onActivityResult 中,图像大小是缩略图的大小。我想要实际的图像大小。怎么办?

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
        Bitmap photo = (Bitmap) data.getExtras().get("data");
        if (CAMERA_REQUEST == 1) {
            ivBeforeLoading.setImageBitmap(photo);
            ivBeforeLoading.setBackgroundResource(0);
            imgBefLoad = photo;
        }
    }
}

【问题讨论】:

标签: android bitmap camera


【解决方案1】:

-你需要获取完整的图片路径,不仅仅是intent中的数据,然后从那个路径获取你的文件,这样你才能得到图片的真实大小。 - 你可以使用一些选择器库,或者你可以检查这个链接

Dialog to pick image from gallery or from camera

你会找到你要找的东西

【讨论】:

    【解决方案2】:

    试试这个 (how do I get file size of temp file in android?)

    File file = new File(selectedPath);
    int file_size = Integer.parseInt(String.valueOf(file.length()/1024));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-08
      • 1970-01-01
      相关资源
      最近更新 更多