更新
Exif 是一种将一些信息数据插入 JPEG 的文件格式。
https://www.media.mit.edu/pia/Research/deepview/exif.html
而Bitmap是数据结构体数据保存行像素数据,没有exif信息。
所以我认为从Bitmap获取exif信息是不可能的。
没有办法获取exif信息。
https://developer.android.com/reference/android/graphics/Bitmap.html
原创
我同意@DzMobNadjib。
我认为轮换信息仅在 exif 中。
要获取 exif,我建议您采取以下步骤。
1.使用文件路径启动相机活动。
查看[保存全尺寸照片]捕获this document。
您可以使用文件路径启动相机活动。相机活动会将图像保存到您传递的文件路径中。
2。在“onActivityResult”中,关注this answer(按照@DzMobNadjib 的建议)
您的代码将如下所示:
(对不起,我没有测试。请仔细阅读并按照上面的答案)
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == Constants.CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
Uri uri = data.getData();
Bitmap bitmap = getAdjustedBitmap(uri);
}
}
}
private Bitmap getAdjustedBitmap(Uri uri) {
FileInputStream is = null;
try {
ExifInterface exif = new ExifInterface(uri.getPath());
int rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
int rotationInDegrees = exifToDegrees(rotation);
Matrix matrix = new Matrix();
if (rotation != 0f) {
matrix.preRotate(rotationInDegrees);
}
is = new FileInputStream(new File(uri.getPath()));
Bitmap sourceBitmap = BitmapFactory.decodeStream(is);
int width = sourceBitmap.getWidth();
int height = sourceBitmap.getHeight();
return Bitmap.createBitmap(sourceBitmap, 0, 0, width, height, matrix, true);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
}
}
}
return null;
}
private static int exifToDegrees(int exifOrientation) {
if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) { return 90; }
else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) { return 180; }
else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) { return 270; }
return 0;
}