I'm trying to make Image captured by the camera by using Camera View lib
Unfortunately, the lib does not support the issue of image rotation in some devices like Samsung.
after long of search, I found out that I can fix it by getting the rotated value like this & this but It not solved my issue.
what I need is if user captured Image in any mode (Default Portrait- Default Landscape- Other Landscape- Other Portrait) is displayed as it.
this is code for getting orientation.
private int getRightRotationAngel(byte[] data) {
ExifInterface exifInterface;
try {
exifInterface = new ExifInterface(new ByteArrayInputStream(data));
} catch (IOException e) {
e.printStackTrace();
return 0;
}
int orientation;
int rotationDegrees = 0;
orientation = exifInterface.getAttributeInt
(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
rotationDegrees = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotationDegrees = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
rotationDegrees = 270;
break;
}
return rotationDegrees;
}
this is code for setting rotation
private void setImageInCorrectRotation(byte[] data) {
int rotateDegree = getRightRotationAngel(data);
Matrix matrix = new Matrix();
Toast.makeText(FrameViewerActivity.this, rotateDegree + "", Toast.LENGTH_SHORT).show();
if (rotateDegree != 0)
matrix.postRotate(rotateDegree);
mCapturedImageCopy = Bitmap.createBitmap(mCapturedImageCopy, 0, 0,
mCapturedImageCopy.getWidth(), mCapturedImageCopy.getHeight(), matrix, true);
showImage(mCapturedImageCopy);
}
hope to get help from anyone
Edit 1: showImage() method work to display the rotated mCapturedImageCopy