0

In my application I get image URLs from web service and show them in ImageView. Some of the images are being shown rotated by 90, 180 or 270 degrees.

I have tried to get orientation from EXIF

ExifInterface exif = null;
try {
exif = new ExifInterface(path);
} catch (IOException e) {
    e.printStackTrace();
}  
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 
                                   ExifInterface.ORIENTATION_UNDEFINED);

but this orientation is always 0. I also tried this

Cursor cursor = context.getContentResolver().query(photoUri,
                new String[]{MediaStore.Images.ImageColumns.ORIENTATION}, null, null, null);

but the cursor is being null.

So how can I get image orientation from it's path in server? Thanks.

  • Please Follow the link: http://stackoverflow.com/questions/12726860/android-how-to-detect-the-image-orientation-portrait-or-landscape-picked-fro – Vishal Raj Dec 09 '15 at 08:53
  • @VishalRaj this is about an image picked from gallery. I want to load it from URL. Can't I get orientation any way? –  Dec 09 '15 at 10:03
  • Not if that info is not stored somewhere. I.e.: in the EXIF metadata. – Phantômaxx Dec 09 '15 at 10:06
  • @FrankN.Stein that info is stored in EXIF metadata. When I download the image manually and watch in properties I can see the rotation angle. But exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL) returns 0 –  Dec 09 '15 at 10:31
  • The `Orientation` tag has only **8** possible values. No angle. The angle information is provided by the software, basing upon the value stored in the tag. – Phantômaxx Dec 09 '15 at 10:36
  • Yes, I was checking the rotation angle with a software. –  Dec 09 '15 at 10:40

0 Answers0