Search code examples
androidorientationandroid-sdk-2.1android-cameraandroid-sdk-1.6

1.6 to 2.1 CameraInfo alternative?


android.Camera.Preferences.setRotation documentation

public void onOrientationChanged(int orientation) {     
    if (orientation == ORIENTATION_UNKNOWN) return;     
    android.hardware.Camera.CameraInfo info = 
        new android.hardware.Camera.CameraInfo();     
    android.hardware.Camera.getCameraInfo(cameraId, info);     
    orientation = (orientation + 45) / 90 * 90;     
    int rotation = 0;     
    if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {         
        rotation = (info.orientation - orientation + 360) % 360;     
    } else {  // back-facing camera         
        rotation = (info.orientation + orientation) % 360;     
    }     
    mParameters.setRotation(rotation); 
}

is there an alternative to Camera.CameraInfo in API level 5 (or better yet even 4)? I am trying to set the rotation of the captured image and I cannot figure out how to get the orientation of the device's camera. pre API level 9 was all camera's orientation fixed or something?


Solution

  • No the camera orientation is at the current status a real mess on Android platform. Even the orientation you get with the camera info is not always the right one (at least for me) in my app i'm letting the user choose if he wants to rotate the camera with a parameter in the settings of the app