我知道在某些设备中捕获的图像被旋转是正常的,但我遇到的问题是,当它们从小米设备捕获时,我无法获得这些图像的旋转值。
可能与这个问题有关
但我尝试了几种建议的解决方案,其中一些适用于我的索尼 Xperia 等其他设备,但没有一个适用于小米。
这些是我获取旋转值的一些尝试,但它们都返回 0 作为旋转值...
public int getRotation () {
// using camera 2 methods to get orientation
int orientation = 0;
int orientation2 = getWindowManager().getDefaultDisplay().getOrientation();
CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
try {
String cameraId = manager.getCameraIdList()[0];
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
orientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
}
catch (Exception e){
e.printStackTrace();
}
return orientation;
}
private int getImageOrientation(){
final String[] imageColumns = { MediaStore.Images.Media._ID, MediaStore.Images.ImageColumns.ORIENTATION };
final String imageOrderBy = MediaStore.Images.Media._ID+" DESC";
Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
imageColumns, null, null, imageOrderBy);
if(cursor.moveToFirst()){
int orientation = cursor.getInt(cursor.getColumnIndex(MediaStore.Images.ImageColumns.ORIENTATION));
cursor.close();
return orientation;
} else {
return 0;
}
}
private int getOrientationUsingExif (String photoPath) {
ExifInterface ei = null;
int orientationDegree = 0;
try {
ei = new ExifInterface(photoPath);
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_UNDEFINED);
switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
orientationDegree = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
orientationDegree = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
orientationDegree = 270;
break;
case ExifInterface.ORIENTATION_NORMAL:
default:
orientationDegree = 0;
}
} catch (IOException e) {
e.printStackTrace();
}
return orientationDegree;
}
任何帮助将不胜感激。