簡體   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