5

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 ....

hacker
  • 8,919
  • 12
  • 62
  • 108

1 Answers1

1

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.

Community
  • 1
  • 1
Evgen
  • 520
  • 4
  • 17
  • how to apply EXIF orientation? – Narendra Singh May 23 '15 at 13:01
  • You have to get orientation, like : int pictureOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); Then you have to check it: if ( pictureOrientation == ExifInterface.ORIENTATION_ROTATE_180){ ... do your rotation code here } You have to check other ExifInterface.ORIENTATION_* params as well. – Evgen May 26 '15 at 10:50
  • Okay, thnx for the reply – Narendra Singh May 26 '15 at 10:54