我知道在某些设备中捕获的图像旋转是正常现象,但是我的问题是,从小米设备捕获图像时,我无法获得这些图像的旋转值。
它可能与this问题有关
但是我尝试了几种建议的解决方案,其中一些可以在其他设备上使用,例如我的Sony 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;
}
任何帮助将不胜感激。