Gaurav Chandra
Gaurav Chandra

Reputation: 111

Cordova Camera Plugin force orientation of camera to portrait

I am using cordova camera plugin latest to take a photo of documents in my cordova android app. The following are the options:

camera.options = {
                quality: 100,
                destinationType: Camera.DestinationType.FILE_URI,
                sourceType: Camera.PictureSourceType.CAMERA,
                allowEdit: false,
                encodingType: Camera.EncodingType.JPEG,
                cameraDirection: 0,
                correctOrientation:false,
                targetWidth:2048,
                targetHeight:2048,
                saveToPhotoAlbum: false
            };

But when I click a photo of my document in portrait mode, the camera flips it 90 degrees and it becomes landscape. I don't want it to flip it. I want it to keep it as it is. Also, I must point out it only happens when my phone is parallel to the ground, when I am clicking a photo of a document placed on the table.

I could not find anything helpful related to this in the camera plugin repo. Can somebody help me?

Upvotes: 10

Views: 12922

Answers (4)

Takao Baltazar
Takao Baltazar

Reputation: 329

I just wanna share on how I solved my issue, on why the cordova camera forces the portrait shot to landscape when rendered on HTML.

var options = {
       quality: 50,
       destinationType: Camera.DestinationType.DATA_URL, //DATA_URL , FILE_URI
       sourceType: Camera.PictureSourceType.CAMERA,
       encodingType: Camera.EncodingType.JPG,
       mediaType: Camera.MediaType.PICTURE,
       targetWidth: 500,
       targetHeight: 500,
       saveToPhotoAlbum: true,
       correctOrientation: true //Corrects Android orientation quirks
} 

The property correctOrientation actually did not completely solved the issue. Instead I change the encodingType to from PNG to JPG.

Upvotes: 11

motatoes
motatoes

Reputation: 926

This question is a bit old but in my case setting correctOrientation: true in the camera options has worked. I have used cordova-plugin-camera.

const cameraOptions = {
    cameraDirection: 1, 
    correctOrientation: true, 
    destinationType: 1
}

navigator.camera.getPicture( 
    function(path) {
        // preview the image in the dom
        // you need to have an <img id="img"> in your dom
        document.querySelector("#img").src = path;
    },
    function(err) {
        console.warn('an error has occured: ' + err);

    }, cameraOptions
)

Upvotes: 6

Bassam
Bassam

Reputation: 856

Please try to remove:

correctOrientation:false

from options.

Upvotes: 1

Gandhi
Gandhi

Reputation: 11935

Looks like this is still an open issue in cordova camera plugin. If none of the workarounds is helping you at this point, then you gotta wait for this request to get resolved so that you can force the orientation lock. Hope it helps.

Upvotes: 1

Related Questions