我正在使用 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 表達式。任何幫助將不勝感激。
2 回答

偶然的你
TA貢獻1841條經驗 獲得超3個贊
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
.

繁星點點滴滴
TA貢獻1803條經驗 獲得超3個贊
所以我實施的答案對我有用,但我不確定它是否適用于所有情況。因此,當我創建圖像時,我設置了一個布爾值來檢查高度是否大于寬度。然后,當我在畢加索中加載圖像時,我有:
Picasso.get() .load(imageURL_1) .fit() .rotate(post.isRotated()?0:90) .transform(new RoundedCornersTransformation(30,30)) .into(imageView1);
就像我說的,這只有在圖像逆時針旋轉 90 度時才有效。如果有更好的解決方法,我歡迎您的回答,但這是我在不訪問 EXIF 信息的情況下所能做的最好的事情。
添加回答
舉報
0/150
提交
取消