Camera: Wrong orientation with Android

Had same problem on Samsung Galaxy S5.

Followed guidance in this thread to arrive solution with following options:

      var options = {
        destinationType: Camera.DestinationType.FILE_URI,
        quality: 75,
        targetWidth:720,
        correctOrientation: true,
        encodingType: Camera.EncodingType.JPEG,
        sourceType: Camera.PictureSourceType.PHOTOLIBRARY
      };
3 Likes

Hey people,
my solution was very simple, i set allowEdit : true and correctOrientation : true for any device.

navigator.camera.getPicture(onSuccess, onFail, {
quality: 60,
destinationType: Camera.DestinationType.DATA_URL,
allowEdit: true,
correctOrientatin: true,
encodingType: Camera.EncodingType.JPEG,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
targetWidth: 3000
});

I hope this helps.

6 Likes

I’ve been searching for this for days now!
Thanks a lot for the solution bro, you rule! :smiley:

Just faced with the same bug with Samsung and cordova-plugin-camera 2.3.1 . I found by myself that it’s enough to set allowEdit : true to prevent auto rotation

Have this issue on Samsung J3, A3 and tablet T580. Is there any way to prevent auto rotation without using allowEdit:true?

Hi Cindy, did you try with correctOrientation: true only ? This solved the wrong orientation problem on my Samsung S7, I didn’t have to play with allowEdit property.

1 Like

Yes I did, but I still had the problem. So it turned out that for certain samsung devices, they have incorrect orientation tag of exif data of the photo. I ended up parsing the exif data and corrected the tag.

Do you mind sharing your code which you have used for changing the exif?

Here is basically the code I use.

1 Like

Do you use this to modify the exif bits of the image? or do you use this code to detect orientation and send it with the picture?

Not sure it will work for you, but you can try this bit (“reverse”) if CorrectOrientation doesn’t work (I don’t use AllowEdit):

    this.camera.getPicture(options).then((imageData) => {
      this.base64Image = "data:image/jpeg;base64," + imageData;

      this.photos.push(this.base64Image);
      this.photos.reverse();
}

It should prevent the picture from flipping.

I use the code to get the exif bits and then modify it by using setUnit16

So you actually modify the jpeg data right? So like:

  1. you read the orientation exif from the image data
  2. calculate the orientation by yourself?
  3. save the exif tag back to the file

For me step 2 isn’t clear. How do you know how much the picture was rotated?

Oh each of the exif orientation number (from 1 to 8) corresponds to a rotation degree, you can check the specific here:
http://sylvana.net/jpegcrop/exif_orientation.html

Indeed, what I don’t get is: if the exif is correct there is no need to “correct” it right? Therefore I asked before if you get the orientation from the file and separately send it along with the file to the server :slight_smile:

oh sure, if the exif is correct then there is no need to ‘correct’. If not correct, then you can modify the orientation tag.

Thanks you saved my day (y)

I’ve created a ticket in the cordova Jira tracker for this issue: https://issues.apache.org/jira/browse/CB-12958

@Michael_Polla is right. correctOrientation: true only worked for me. thanks

3 Likes

Hi everybody.
Now it s 2018, and it seems that this issue is still open. Someone has found a universal solution for this problem?
Please let me know
Thx