Photo capture

1navigator.camera.getPicture(onPhotoSuccess, onPhotoFail, {
2  quality: 60,
3  destinationType: navigator.camera.DestinationType.DATA_URL,
4  saveToPhotoAlbum: true,
5  targetWidth: 1024,
6  targetHeight: 1024
7});
destinationType: navigator.camera.DestinationType.DATA_URL,

either DATA_URL (base64 encoded) or FILE_URI (file path)

saveToPhotoAlbum: true,

indicate if a copy of the photo is saved to device album

// Other options

sourceType : Camera.PictureSourceType.CAMERA

either from CAMERA, PHOTOLIBRARY or SAVEDPHOTOALBUM

allowEdit : true,

In iPhone, this allow users to crop or rotate the photo before passing it back to the app.

Let’s make this a module.

 1Camera.prototype.getPicture = function(callback)
 2{
 3  var onPhotoSuccess = function(imageData)
 4  {
 5    var imageSrc = "data:image/jpeg;base64," + imageData
 6    if (callback) callback(imageSrc);
 7  }
 8  var onPhotoFail = function(message)
 9  {
10    alert('Camera Failed: ' + message);
11  }
12  navigator.camera.getPicture(onPhotoSuccess, onPhotoFail, {
13    quality: 20,
14    destinationType: navigator.camera.DestinationType.DATA_URL,
15    saveToPhotoAlbum: true,
16    targetWidth: 1024,
17    targetHeight: 1024
18  });
19}
20

What’s next? We’re going to take a look at “Capture video”.

overlaied image when clicked on thumbnail

Makzan | Mobile web app dev with phonegap | Table of Content