var pictureSource; // Picture sour...">

Select an image from a camera or gallery using a phone saver

<script type="text/javascript" charset="utf-8">



var pictureSource;   // Picture source

var destinationType; // Sets the format of returned value 

// Wait for PhoneGap to connect with the device


document.addEventListener("deviceready", onDeviceReady, false);


// PhoneGap is ready to be used!

function onDeviceReady() 

{


   pictureSource = navigator.camera.PictureSourceType;

    destinationType = navigator.camera.DestinationType;


}

function capturePhoto() {

    navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 25, destinationType: 
Camera.DestinationType.FILE_URI });

}

function onPhotoURISuccess(imageURI) {

    createFileEntry(imageURI);
}

function createFileEntry(imageURI) {

    window.resolveLocalFileSystemURI(imageURI, copyPhoto, fail);    
}

function copyPhoto(fileEntry) {

    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys) { 
        fileSys.root.getDirectory("photos", {create: true, exclusive: false}, 

function(dir) { 

  fileEntry.copyTo(dir, "file.jpg", onCopySuccess, fail); 

            }, fail); 
    }, fail); 
}

function onCopySuccess(entry) {

    console.log(entry.fullPath)
}

function fail(error) {

    console.log(error.code);
}


    </script>
+5
source share
1 answer

You must use the PhoneGap 2.0.0 camera object . The documentation provides a complete example of capturing a photograph.

It also navigator.camera.getPicture( cameraSuccess, cameraError, [ cameraOptions ] );takes a photo using the camera or extracts a photo from the device’s album. The image is returned as a base64 encoded string or as the URI of the image file.

Hope this helps.

+2
source

All Articles