0

My app ask the user to take a photo and then saves it.

I have noticed that Samsung Galaxy S2 takes a portrait photo

but when I save it to the server I see it in landscape only in the server.

(even though it was taken in portrait).

It doesn't happen for me with other phones (Samsung S4, Nexus 5).

When I look at the photo gallery I see the photo in portrait.

Update

The weird thing is that in my java code it seemed to be portrait orientation

so I really don't get it:

            if (getContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
                //a             
}else {
                //b
            }

But i saw something odd: the settings and other native dialog are all landscape when using S2 camera. see attachment:

Update2

I have checked exif.getAttributeInt(ExifInterface.TAG_ORIENTATION and got 6 ( ExifInterface.ORIENTATION_ROTATE_90)

So i have tried to set this to ORIENTATION_ROTATE_270 or ORIENTATION_NORMAL

but it didn't help

    ExifInterface exif;
    try {
      exif = new ExifInterface(imageFilename);
      int orientation =
          exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
      exif.setAttribute(ExifInterface.TAG_ORIENTATION,
          String.valueOf(ExifInterface.ORIENTATION_ROTATE_270));
      exif.saveAttributes();
      orientation =
          exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
      boolean b = orientation == Configuration.ORIENTATION_LANDSCAPE;

    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

enter image description here

Elad Benda
  • 35,076
  • 87
  • 265
  • 471
  • you should try it. this problem is happening with samsung devices. http://stackoverflow.com/questions/13245556/exif-orientation-tag-value-always-0-for-image-taken-with-portrait-camera-app-and – GovindRathod May 15 '14 at 09:47
  • GovindRathod please see my update – Elad Benda May 15 '14 at 10:57

1 Answers1

0

You are right. The documentation of Camera.Parameters.setRotation() is very clear:

The camera driver may set orientation in the EXIF header without rotating the picture. Or the driver may rotate the picture and the EXIF thumbnail. If the Jpeg picture is rotated, the orientation in the EXIF header will be missing or 1 (row #0 is top and column #0 is left side).

The solution is to actually perform rotation of the pictures before upload, or maybe on the server (the choice depends on your product requirements). You can use a Java MediaUtil library, see e.g. https://stackoverflow.com/a/15302674/192373.

Community
  • 1
  • 1
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • thanks. why does setting the exif tag to be "rotation_undefined" or "rotation_noraml"? I managed to set it to the desired value, but the image is still rotated on the server. – Elad Benda May 16 '14 at 05:34
  • I'm confused. Why do you suggest `The solution is to actually perform rotation of the pictures before upload` and not using `public void onOrientationChanged(int orientation)` ? – Elad Benda May 16 '14 at 05:55
  • In which situation did you see "rotation_undefined"? – Alex Cohn May 16 '14 at 16:07
  • Let me explain. Even when EXIF flag defines the correct orientation, some image viewers ignore this flag and display the image rotated. You cannot fix the world, so if you want your images to be universally correct, you can perform the rotation according to EXIF flags (or to device orientation). – Alex Cohn May 16 '14 at 16:11
  • "rotation_undefined" when i check the tags on my Samsung Note 2 – Elad Benda May 17 '14 at 14:01
  • thanks. how about using Camera object instead of "action intent" and there setting "setRotation" - will this change the preview before capture screen or what actually does it do? – Elad Benda May 17 '14 at 14:09
  • The way the device treats rotated capture is the same for Camera object and `MediaStore.ACTION_IMAGE_CAPTURE` intent. – Alex Cohn May 17 '14 at 15:11
  • can you please elaborate? I didn't get your last sentence – Elad Benda May 17 '14 at 20:28
  • what will "setRotation" do to my jpeg or to the camera preview? – Elad Benda May 17 '14 at 20:29
  • 1
    Camera.Parameters.setRotation() does not effect the preview. Its purpose is to rotate the captured Jpeg. Some devices actually rotate the image, but others only set the EXIF flag. There is a different API, Camera.setOrientation(), which takes care of preview, but not takePicture(). – Alex Cohn May 18 '14 at 05:36