繁体   English   中英

为什么在Android的ExifInterface上出现File not found错误?

[英]Why am I getting File not found error for ExifInterface with Android?

我正在使用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)

我只需要它返回图像旋转了多少,但由于它抛出了File not found表达式,因此始终返回0。 任何帮助将不胜感激。

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。 它不是文件系统上的文件。

下载文件,然后使用AndroidX版本的ExifInterface进行检查。

或者,如果要在ImageView显示这些图像,请使用图像加载库(例如Glide或Picasso),在显示图像时应考虑EXIF方向标头。

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

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

就像我说的那样,这仅在图像逆时针旋转90度时有效。 如果有更好的解决方法,欢迎您回答,但这是我最好的选择,而无需访问EXIF信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM