2 回答

TA貢獻1833條經驗 獲得超4個贊
大約有 20 億臺 Android 設備,分布在大約 20,000 種設備型號中。這些設備型號中預裝了數十個(如果不是數百個)相機應用程序。用戶可以下載和安裝許多其他相機應用程序。
您的代碼可能會啟動其中任何一個。
在相機意圖中,我的華為 P20 Pro 上的圖像預覽始終處于縱向模式
這就是數百個相機應用程序的行為。
在另一臺測試設備上,預覽圖像(您可以決定是否要重新拍攝圖像的圖像)也卡在“初始”旋轉中,看起來很難看。
這就是數百個相機應用程序的行為。
相機應用程序不需要以這種方式運行。當然,相機應用程序根本不需要預覽圖像。
有解決方案嗎?
如果你想使用ACTION_IMAGE_CAPTURE
,不。這數百個相機應用程序的行為取決于這些相機應用程序的開發人員,而不是您。
拍照還有其他選項,例如直接使用相機 API 或使用 Fotoapparat 或 CameraKit-Android 等第三方庫。

TA貢獻1793條經驗 獲得超6個贊
用于ExifInterface在解碼時檢查圖像的方向。然后旋轉圖像以獲得正確方向的所需圖像。
BitmapFactory.Options options = new BitmapFactory.Options();
options.inMutable = true;
Bitmap decoded = BitmapFactory.decodeFile(filePath, options);
if (decoded == null) return null;
try {
ExifInterface exif = new ExifInterface(filePath);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
int rotation = 0;
if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
rotation = 90;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
rotation = 270;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
rotation = 180;
}
if (rotation != 0) {
Matrix matrix = new Matrix();
matrix.postRotate(rotation);
Bitmap newBitmap = Bitmap.createBitmap(decoded, 0, 0, decoded.getWidth(),
decoded.getHeight(), matrix, true);
decoded.recycle();
Runtime.getRuntime().gc();
decoded = newBitmap;
}
} catch (IOException e) {
e.printStackTrace();
}
如果您想使用支持庫來支持 API 級別較低的設備,請使用以下依賴項:
implementation 'com.android.support:exifinterface:27.1.1'
并導入 android.support.media.ExifInterface
添加回答
舉報