Hi we know that we have lots of devices available in Android market with different-2 resolutions and functionalities like we have some issue with samsung and lg devices while capturing images from camera, we basically gets the wrong orientation of captured images because these devices works with landscape mode. So if you want to manage image orientation for all devices you can use the following codes here :
File newfile = new File(new URI(fileUri.toString()));
String filePath = newfile.getAbsolutePath();
int rotate = 0;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
Bitmap image = BitmapFactory.decodeFile(filePath, options);
try {
ExifInterface exif = new ExifInterface(
newfile.getAbsolutePath());
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
}
Log.v("", "Exif orientation: " + orientation);
} catch (Exception e) {
e.printStackTrace();
}
Matrix matrix = new Matrix();
matrix.postRotate(rotate);
image = Bitmap.createBitmap(image, 0, 0, image.getWidth(), image.getHeight(), matrix, true);
Here we get the stored image from device storage and checked its orientation if orientation is changed then we convert it back to normal and then we will apply it to image by using Matrix.
0 Comment(s)