0

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.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • Please be more specific. Do you get the image file? Can you access it via ExifInterface? Does this **ei** contain TAG_ORIENTATION? Does this tag have one of the expected values (ORIENTATION_ROTATE_90, ...)? – Alex Cohn Sep 24 '18 at 16:53
  • yes, i got the image and can access it via ExifInterface, it does contain TAG_ORIENTATION but the value it has is the equivalent to 0, as if the image was not rotate – Juan Monsalve Sep 24 '18 at 17:11
  • Now, how was this image file obtained? Was it captured in the stock Camera app, or in a 3rd party app, or via the ACTION_IMAGE_CAPTURE intent? – Alex Cohn Sep 24 '18 at 17:16
  • i got that picture using android.hardware.Camera -> camera.takePicture(...) – Juan Monsalve Sep 24 '18 at 20:34

0 Answers0