21

I'm using Sencha Touch and Phonegap to display a picture recorded with the camera. When taking a picture on an iphone via cordova2.7.0, the picture is drawn with the correct orientation. But using samsung s3, the picture will be leant by -90°(only for portrait images).

navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 25, 
          destinationType: destinationType.FILE_URI,
         targetWidth: 120,
         targeHeight: 120,
          correctOrientation: true,
          sourceType: source });

I use the above code to take picture. The portrait images took from camera displays in correct orientation, issue happens only for the portrait images took from the gallery. Is there is any way to solve this problem?

Linson
  • 655
  • 1
  • 7
  • 21

7 Answers7

15

It simply solved my issue by adding the parameter encodingType. Now the code looks like

var encodingType = navigator.camera.encodingType.PNG;
var destinationType = navigator.camera.DestinationType;
var destinationType = navigator.camera.DestinationType;
var source = navigator.camera.PictureSourceType;
navigator.camera.getPicture(onPhotoURISuccess, onFail, {
  quality: 50,
  destinationType: destinationType.FILE_URI,
  encodingType: encodingType.PNG,
  targetWidth: 120,
  targeHeight: 120,
  correctOrientation: true,
  sourceType: source });
Linson
  • 655
  • 1
  • 7
  • 21
  • can you please explain little bit on your issue. – Linson May 20 '16 at 11:04
  • Image orientation get changed of images which are captured by samsung edge S6, A5 camera(default not using cordova plugin). It works fine for screenshot and picure taken by camera(using cordova plugin). – parth.hirpara May 21 '16 at 02:05
  • 1
    encodingType.PNG is not defined – Sameera R. May 25 '16 at 06:26
  • `encodingType` is an enum of `Camera`, so you want to get it with `Camera.EncodingType.PNG` or maybe `navigator.camera.encodingType.PNG`, depending on your framework. It really only is an integer though, so look at [a documentation](https://www.npmjs.com/package/cordova-plugin-camera#module_Camera.EncodingType) and use the according value (i.e. `0`for JPEG, `1` for PNG). With `correctOrientation : true` passed in the options object, the issue is solved with one of the two landscape orientation. So I guess the plugin uses the gyroscope to get a sense of what is "up". – Sumi Straessle Feb 26 '17 at 12:15
  • A little late but it's "EncodingType" for me, not lowercase "encodingType". – dav Jul 25 '17 at 12:45
5

It simply solved my issue by adding the parameter correctOrientation. Now the code looks like :

navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, 
destinationType: destinationType.FILE_URI,
correctOrientation: true,
sourceType: source });
}
1

I was having this issue with my Samsung Galaxy S5 as well, but switched encodingType from PNG to JPEG (in combination with a targetWidth) and now it has the correct orientation.

One of the commenters on this forum post mentioned it is due being out of memory. http://forum.ionicframework.com/t/camera-wrong-orientation-with-android/8583

try {
    bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    this.orientationCorrected = true;
} catch (OutOfMemoryError oom) {
    this.orientationCorrected = false;
}
PaulAndrewLang
  • 379
  • 3
  • 4
1

New update for cordova plugin that solves this issues.

cordova plugin rm org.apache.cordova.camera
cordova plugin add https://github.com/apache/cordova-plugin-camera

just re-install the plugin, here is the fixes they published:

Add orientation support for PNG to Android (closes #45)

Liad Livnat
  • 7,435
  • 16
  • 60
  • 98
0

correctOrientation: true, add this its work for me

jagadeesh
  • 17
  • 2
0

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
});
Amir
  • 1,066
  • 1
  • 13
  • 26
0

This seems to be a device specific issue. For example, with the following code:

var options = {
    quality: 50,
    correctOrientation: true,
    allowEdit: false,
    destinationType: Camera.DestinationType.FILE_URI,
    sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
    mediaType: Camera.MediaType.PICTURE,
    encodingType: Camera.EncodingType.JPEG
};
navigator.camera.getPicture(success,failure,options);

This works on a Nexus 5 and orients the returned image properly, however it doesn't work on a Samsung Tab A and the image orientation is not corrected.

My only workaround is to set allowEdit to true as the edited photo is returned in the proper orientation.

Tom Kincaid
  • 4,887
  • 6
  • 47
  • 72