0

In my application Image is getting rotated when it is clicked from camera in portrait mode, this happens only for samsung device and for the rest it works fine. I implemented following code after researching in stack overflow:

ExifInterface ei = new ExifInterface(imgFile.getPath());
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);

switch (orientation) {
case ExifInterface.ORIENTATION_UNDEFINED:
mBitmap = rotateImage(bitmap, 90);
break;
}

This code helps me to fix that issue in samsung but now when image is clicked from camera it is getting rotated in other devices due to this piece of code.

Please let me know how can I fix this issue.

keshav kowshik
  • 2,354
  • 4
  • 22
  • 45
  • As far as documentations goes: `getAttributeInt` "Returns the integer value of the specified tag. If there is no such tag in the image file or the value cannot be parsed as integer, return defaultValue.", This means that either the tag is not defined, and ExifInterface.ORIENTATION_UNDEFINED (0) is returned, or your switch is not handling the ORIENTATION_(something) cases. Add a default clause, and Log the `orientation` returned. – Bonatti Aug 01 '16 at 13:47
  • Ok thanks a lot.. will do that.. I have checked the value of orientation before switch it says 0.. – keshav kowshik Aug 01 '16 at 13:56
  • Also note that this "issue" is old, [since 2012](http://stackoverflow.com/questions/13245556/exif-orientation-tag-value-always-0-for-image-taken-with-portrait-camera-app-and) it is know that Samsung wont save Exif data properly. [Even the Exif standard](https://en.wikipedia.org/wiki/Exchangeable_image_file_format#Problems) has issues that creates incompatibility cases. Since Samsung wont honor the Exif interface, you can either edit that setting yourself (if you are asking for a Camera Intent, use the device orientation) or check Bitmap height/width, and flip the image accordingly. – Bonatti Aug 01 '16 at 14:12
  • OK ok.. Thanks a lot – keshav kowshik Aug 01 '16 at 14:25

2 Answers2

0

If you are confident that this is only Samsung device issue, you can check for the device make and add that to your if(...) condition. This library can be of great help.

Also have a look at Jared Rummler's answer to this question:

But if this is a device specific issue, it may occur on other devices too or may be eventually corrected in newer Samsung device OS updates. Keep a good check on that.

Community
  • 1
  • 1
0

pass that return degrees to convert the bitmap,

try {
       ExifInterface exif = new ExifInterface(imgPath);  
        String rotationAmount = exif
                .getAttribute(ExifInterface.TAG_ORIENTATION);
        if (!TextUtils.isEmpty(rotationAmount)) {
            int rotationParam = Integer.parseInt(rotationAmount);
            switch (rotationParam) {
            case ExifInterface.ORIENTATION_NORMAL:
                return 0;
            case ExifInterface.ORIENTATION_ROTATE_90:
                return 90;
            case ExifInterface.ORIENTATION_ROTATE_180:
                return 180;
            case ExifInterface.ORIENTATION_ROTATE_270:
                return 270;
            default:
                return 0;
            }
        } else {
            return 0;
        }
    } catch (Exception ex) {
        return 0;
    }
prakash
  • 1,413
  • 1
  • 21
  • 33