Android getting an image from gallery comes rotated
You could use ExifInterface to modify the orientation:
public static Bitmap modifyOrientation(Bitmap bitmap, String image_absolute_path) throws IOException {
ExifInterface ei = new ExifInterface(image_absolute_path);
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
return rotate(bitmap, 90);
case ExifInterface.ORIENTATION_ROTATE_180:
return rotate(bitmap, 180);
case ExifInterface.ORIENTATION_ROTATE_270:
return rotate(bitmap, 270);
case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
return flip(bitmap, true, false);
case ExifInterface.ORIENTATION_FLIP_VERTICAL:
return flip(bitmap, false, true);
default:
return bitmap;
}
}
public static Bitmap rotate(Bitmap bitmap, float degrees) {
Matrix matrix = new Matrix();
matrix.postRotate(degrees);
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}
public static Bitmap flip(Bitmap bitmap, boolean horizontal, boolean vertical) {
Matrix matrix = new Matrix();
matrix.preScale(horizontal ? -1 : 1, vertical ? -1 : 1);
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}
In order to get absolute path of your images from their uri, check this answer
Android: Bitmaps loaded from gallery are rotated in ImageView
Have you looked at the EXIF data of the images? It may know the orientation of the camera when the picture was taken.
Related Topics
Importing Google-Play-Service Library Showing a Red X Next to This Reference Android
Get Referrer After Installing App from Android Market
Which Is the Best Way to Add a Button
Ideal Way to Set Global Uncaught Exception Handler in Android
How to Serialize an Object and Save It to a File in Android
How to Hide Soft Keyboard When Activity Starts
Custom Getfilter in Custom Arrayadapter in Android
Recyclerview Horizontal Scroll Snap in Center
How to Calculate Distance Between Two Locations Using Their Longitude and Latitude Value
Listadapter Not Updating Item in Recyclerview
How to Set a Gradient Background in a Material Button from Material Components
How to Change the Text Color of Menu Item in Android
Convert a PDF Page into Bitmap in Android Java
This Version of the Application Is Not Configured for Billing Through Google Play
Android - How to Receive Broadcast Intents Action_Screen_On/Off