I am dealing with camera images in my app which actually get as urls.The camera app is in portrait mode.So the images are sometimes left rotated or right rotated.I know that we can use EXIF for normal image orientation from gallery, there we can check the exif value and do appropriate changes.Basicaly this is the code for exif
ExifInterface exif = new ExifInterface("filepath");
exif.getAttribute(ExifInterface.TAG_ORIENTATION);
So my question is what is the filepath in my case, is it the url itself or should i create a file for that.. Any help will be greatly appreciated ....
First, you have to get Uri in onActiviryResult, like here
Get image Uri in onActivityResult after taking photo?
Then, when you have Uri you can get filepath like this:
String filepath = getRealPathFromURI(someUri);
public String getRealPathFromURI(Uri contentUri) {
String res = null;
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(contentUri, proj, null, null, null);
if(cursor != null && cursor.moveToFirst()){;
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
res = cursor.getString(column_index);
}
cursor.close();
return res;
}
Then, if filepath is not null and not empty, you can get EXIF data, check it and rotate image if it needs.
Hope it will help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With