i know it is normal in some devices the image captured gets rotated but the problem i have is that i can´t get the rotation value of that images when they´re captured from a Xiaomi device.
It can be related to this question
but i´ve tried several suggested solutions, some of them work on other devices like my Sony Xperia but none of them work on the Xiaomi.
those are some of my attempts to get rotation value, but all of them return 0 as rotation value...
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;
}
any help will be highly appreciated.