8

I have developed an app using Phone Gap version 0.9.3...

When I open camera in my app ,it always opens in landscape mode and, on capture, the image is returned in landscape format...

How can I change the mode of camera to portrait

navigator.camera.getPicture(onsuccess, fail, {quality: 45,destinationType : Camera.DestinationType.DATA_URL, sourceType: src},img_id);

function onsuccess(imageData) {
    localStorage.setItem("image_captured","Yes");
    $('#'+imgID).attr('src', 'data:image/jpeg;base64,' + imageData);
    $("#"+imgID+"_IMG").attr('src', 'data:image/jpeg;base64,' + imageData);
}

In manifest i had mention:

<activity android:name="com.android.camera.Camera"
    android:screenOrientation="portrait">
</activity>

Please help me in this...

a.ch.
  • 8,285
  • 5
  • 40
  • 53
Sandeep P
  • 4,291
  • 2
  • 26
  • 45

4 Answers4

18

Try this : correctOrientation: true

function getPhoto(source) {

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

}
Akhilesh Kumar
  • 849
  • 1
  • 15
  • 28
  • 2
    correctOrientation is currently ignored on most devices (android included) – Per Hornshøj-Schierbeck Aug 15 '14 at 08:03
  • @PerHornshøj-Schierbeck I'm also facing the issue that a picture taken in portrait mode is returned in landscape mode when trying to display it in HTML right after the picture has been taken. How do you fix that? "correctOrientation" does not help and seems to be ignored (Emulator/Nexus and Galaxy S3), that's true... – Philipp Rieber Aug 15 '14 at 15:34
  • @PerHornshøj-Schierbeck Thanks, I've also added a solution - for me the "correctOrientation" parameter works just fine now. – Philipp Rieber Aug 17 '14 at 11:57
7

photo orientation is not stored when returning an image in base64 format (all EXIF data is stripped).

You should use the accelerometer or screen orientation to "know" if the image was taken in portrait or landscape and then display it accordingly.

BigBalli
  • 762
  • 1
  • 6
  • 10
6

The "correctOrientation" parameter works fine for me - but only if you're also using the "targetWidth" and "targetHeight" parameters (e.g. set them to "800"). It seems that some devices may not have enough memory to rotate a full resolution picture.

Update: Here's a nice article with useful information about memory, scaling and EXIF issues with the Phonegap Camera code: http://simonmacdonald.blogspot.ca/2012/07/change-to-camera-code-in-phonegap-190.html

Philipp Rieber
  • 1,531
  • 17
  • 25
0

I've solved my problem my saving as file url instead. The file will be placed in a temporally folder along with correct EXIF data. There might be some devices where you have to manually delete the files when closing the application though.

When referencing the file url instead of the data, the img seem to get displayed correctly.

Per Hornshøj-Schierbeck
  • 15,097
  • 21
  • 80
  • 101