Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 360
Gaurav Chandra Avatar asked May 06 '16 13:05

Gaurav Chandra


3 Answers

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.

like image 145
Takao Baltazar Avatar answered Nov 17 '22 19:11

Takao Baltazar


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
)
like image 41
motatoes Avatar answered Nov 17 '22 19:11

motatoes


Please try to remove:

correctOrientation:false

from options.

like image 1
Bassam Avatar answered Nov 17 '22 21:11

Bassam