【问题标题】:Why am I getting File not found error for ExifInterface with Android?为什么我在 Android 上遇到 ExifInterface 的 File not found 错误?
【发布时间】:2019-11-05 15:31:30
【问题描述】:

我正在使用 Firebase 为我的 Android 应用存储图像。然后图像会出现在我的应用程序中的回收站视图中。这一切都很好,但是,某些图像出现在侧面。特别是那些用 Galaxy S7 拍摄的。

我知道我需要从图像中获取 exif 信息,但是当我尝试时出现未找到文件的错误,我该怎么办?

private int getImageOrientation(String imagePath){
        int rotate = 0;
        try {
            File imageFile = new File(imagePath);

            ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
            int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

            switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_270:
                    rotate = 270;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    rotate = 180;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_90:
                    rotate = 90;
                    break;
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return rotate;
    }
W/System.err: java.io.FileNotFoundException: /https:/firebasestorage.googleapis.com/v0/b/pickit-d193d.appspot.com/o/posts%2Ff12e73ad-9bc5-4485-90e5-927dbf8539a5.jpg?alt=media&token=9f92c0d7-0518-4721-a7b5-235c1fb3cc76 (No such file or directory)

我只需要它来返回图像旋转了多少,但它总是返回 0,因为它会抛出一个 File not found 表达式。任何帮助将不胜感激。

【问题讨论】:

    标签: java android firebase picasso exif


    【解决方案1】:

    https:/firebasestorage.googleapis.com/v0/b/pickit-d193d.appspot.com/o/posts%2Ff12e73ad-9bc5-4485-90e5-927dbf8539a5.jpg?alt=media&token=9f92c0d7-0518-4721-a7b5-235c1fb3cc76 是一个 HTTPS URL。它不是文件系统上的文件。

    下载文件,然后使用the AndroidX edition of ExifInterface 进行检查。

    或者,如果您将在 ImageView 中显示这些图像,请使用 Glide 或 Picasso 等图像加载库,它们在显示图像时应考虑 EXIF 方向标头。

    【讨论】:

    • 我正在使用 Picasso 加载这些图像,但这并不能解决问题,我也尝试过使用 glide。下载文件也不会显着降低应用程序的速度吗?我正在使用一个回收器视图,每个卡片视图有两个图像。有没有办法直接从firebase获取exif信息?
    • @Bjorn:“我正在使用 Picasso 加载这些图像,但这并不能解决问题,我也尝试过使用 glide”——然后我怀疑 ExifInterface 会帮助你。 “而且下载文件不会显着降低应用程序的速度吗?” -- 嗯,您已经通过 Glide 或 Picasso 下载图像。 “有没有办法直接从firebase获取exif信息?” -- 抱歉,我不是 Firebase 专家。
    • 我正在尝试将此函数的结果传递给毕加索的 .rotate() 函数。
    • @Bjorn:最后我知道,这些库应该为您处理 EXIF 标头。 Glide 确实可以——例如,参见 thisthis
    • 我认为我遇到了与 link 类似的问题,但我不确定是什么可以删除 exif 信息。
    【解决方案2】:

    所以我实施的答案对我有用,但我不确定它是否适用于所有情况。因此,当我创建图像时,我设置了一个布尔值来检查高度是否大于宽度。然后,当我在 picasso 中加载图像时,我有:

    Picasso.get()
                    .load(imageURL_1)
                    .fit()
                    .rotate(post.isRotated()?0:90)
                    .transform(new RoundedCornersTransformation(30,30))
                    .into(imageView1);
    

    就像我说的,这仅在图像逆时针旋转 90 度时才有效。如果有更好的解决方案,我欢迎您的回答,但这是我在不访问 EXIF 信息的情况下能做的最好的事情。

    【讨论】:

      猜你喜欢
      • 2011-08-31
      • 2021-01-02
      • 2021-11-23
      • 1970-01-01
      • 2019-10-05
      • 1970-01-01
      • 1970-01-01
      • 2012-03-25
      • 1970-01-01
      相关资源
      最近更新 更多