UPDATE
Exif is a file format that inserts some information data to JPEG.
https://www.media.mit.edu/pia/Research/deepview/exif.html
And Bitmap
is data structior data holds row pixel data, no exif info.
So I think it is impossible to get exif info from Bitmap
.
There is no method to get exif info.
https://developer.android.com/reference/android/graphics/Bitmap.html
ORIGINAL
I agree with @DzMobNadjib .
I think the info of rotation is only in exif.
To take exif, I recommend you to take following steps.
1. Start camera activity with file path.
See [Save the Full-size Photo] capture of this document.
You can start the camera activity with file path.The camera activity will save the image to the file path that you passed.
2. In 'onActivityResult', Follow this answer (as @DzMobNadjib suggested)
Your code will be like this:
(Sorry I'm not tested. Please read carefuly and follow the above answer)
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == Constants.CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
Uri uri = data.getData();
Bitmap bitmap = getAdjustedBitmap(uri);
}
}
}
private Bitmap getAdjustedBitmap(Uri uri) {
FileInputStream is = null;
try {
ExifInterface exif = new ExifInterface(uri.getPath());
int rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
int rotationInDegrees = exifToDegrees(rotation);
Matrix matrix = new Matrix();
if (rotation != 0f) {
matrix.preRotate(rotationInDegrees);
}
is = new FileInputStream(new File(uri.getPath()));
Bitmap sourceBitmap = BitmapFactory.decodeStream(is);
int width = sourceBitmap.getWidth();
int height = sourceBitmap.getHeight();
return Bitmap.createBitmap(sourceBitmap, 0, 0, width, height, matrix, true);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
}
}
}
return null;
}
private static int exifToDegrees(int exifOrientation) {
if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) { return 90; }
else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) { return 180; }
else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) { return 270; }
return 0;
}