Camera orientation issue in Android Camera orientation issue in Android android android

Camera orientation issue in Android


There are quite a few similar topics and issues around here. Since you're not writing your own camera, I think it boils down to this:

some devices rotate the image before saving it, while others simply add the orientation tag in the photo's exif data.

I'd recommend checking the photo's exif data and looking particularly for

ExifInterface exif = new ExifInterface(SourceFileName);     //Since API Level 5String exifOrientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);

Since the photo is displaying correctly in your app, i'm not sure where the problem is, but this should definitely set you on the right path!


I just encountered the same issue, and used this to correct the orientation:

public void fixOrientation() {    if (mBitmap.getWidth() > mBitmap.getHeight()) {        Matrix matrix = new Matrix();        matrix.postRotate(90);        mBitmap = Bitmap.createBitmap(mBitmap , 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), matrix, true);    }}

If the width of the Bitmap is greater than the height, the returned image is in landscape, so I rotate it 90 degrees.

Hope it helps anyone else with this issue.


There are two things needed:

  1. Camera preview need the same as your rotation. Set this by camera.setDisplayOrientation(result);

  2. Save the picture captured as your camera preview.Do this via Camera.Parameters.

    int mRotation = getCameraDisplayOrientation();Camera.Parameters parameters = camera.getParameters();parameters.setRotation(mRotation); //set rotation to save the picturecamera.setDisplayOrientation(result); //set the rotation for preview cameracamera.setParameters(parameters);

Hope that helps.