Set camera width and height phonegap camera

15,730

Solution 1

Try this one my friend. remove allowEdit : true

camera: function() {
        navigator.camera.getPicture(onSuccess, onFail, {
            quality: 50,
            targetWidth: 512,
            targetHeight: 512,
            destinationType: navigator.camera.DestinationType. DATA_URL,
            saveToPhotoAlbum: true,
            correctOrientation: true
        });
    }

Solution 2

How about changing your mind to resizing image after it has been captured?

Useful article for resizing image with HTML5 Canvas

Share:
15,730
Matthijs
Author by

Matthijs

Software Developer at 24i profile for Matthijs on Stack Exchange, a network of free, community-driven Q&A sites http://stackexchange.com/users/flair/3445314.png

Updated on June 07, 2022

Comments

  • Matthijs
    Matthijs almost 2 years

    I am currently in the process of creating a mobile app that uses the Phonegap (Cordova) camera plugin. It correctly captures the image and displays it where I want to, but I can't seem to set the targetWidth and targetHeight options, as described.

    targetWidth: Width in pixels to scale image. Must be used with targetHeight. Aspect ratio remains constant. (Number)

    targetHeight: Height in pixels to scale image. Must be used with targetWidth. Aspect ratio remains constant. (Number)

    As I understand, this will change the image-width and height on output. They, however, don't seem to be working.

    A suggestion that I found while researching for a solution, said to use the optional parameter allowEdit. In this I could get the user to select a pre-set squared image. This however, doesn't seem to work either.

    See my code below for reference.

    camera: function() {
        //Fire up the camera!
        navigator.camera.getPicture(onSuccess, onFail, {
            destinationType: Camera.DestinationType.DATA_URL,
            allowEdit: true,
            targetWidth: 512,
            targetHeight: 512
        });
    },
    

    Neither of the attemps succeeded in what I wanted; a fixed width and height for the image captured.

    How can I set the image width and height on this image?