I'm passing a bitmap via bundle on onActivityResult
from a camera.
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "picture");
mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
startActivityForResult(intent, REQUEST_TAKE_PHOTO);
I can get the bitmap:
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), mCapturedImageURI);
However, I've noticed that the image is rotated on some devices. After searching posts on here, the typical solution seemed to get the rotation via:
String path = mCapturedImageURI.getPath();
ExifInterface exif = new ExifInterface(path);
int rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
Unfortunately, my int rotation
is always 0 even though the bitmap is rotated.
I've also tried this which worked when I uploaded a picture already on the device but the orientation is still 0:
String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION};
Cursor cur = managedQuery(mCapturedImageURI, orientationColumn, null, null, null);
if (cur != null && cur.moveToFirst()) {
orientation = cur.getInt(cur.getColumnIndex(orientationColumn[0]));
}
Anyone see anything I may be doing wrong here? Or another workaround?
Generally, the bitmap is rotated 90 degrees counter-clockwise with the back camera and 90 degrees clockwise with the front camera. Works ok on Moto G. Rotated on Galaxy S3 and LG G2.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…