Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image took from gallery is displayed in different orientation while using phonegap in android

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?

like image 478
Linson Avatar asked Jul 19 '13 10:07

Linson


3 Answers

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 });
like image 73
Linson Avatar answered Nov 11 '22 21:11

Linson


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 });
}
like image 5
Vishal Panchal Avatar answered Nov 11 '22 19:11

Vishal Panchal


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;
}
like image 1
PaulAndrewLang Avatar answered Nov 11 '22 21:11

PaulAndrewLang