Skip to content

Instantly share code, notes, and snippets.

@bhuber
Created January 27, 2012 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhuber/1690549 to your computer and use it in GitHub Desktop.
Save bhuber/1690549 to your computer and use it in GitHub Desktop.
Phonegap Camera Function
var defaultPictureOptions = {
quality : 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.CAMERA
/* ,
targetWidth: 100,
targetHeight: 100
*/
};
var phonegapPic = function(onSuccess, onFail, photoType) {
if (!navigator) { console.log('no navigator obj'); return false; }
if (!navigator.camera) { console.log('no navigator.camera obj'); return false; }
if (!navigator.camera.getPicture) { console.log('no navigator.camera.getPicture'); return false; }
photoType = photoType || "camera";
console.log('taking picture...');
var opts = $.extend({}, defaultPictureOptions, {
sourceType: (photoType === "camera") ? Camera.PictureSourceType.CAMERA : Camera.PictureSourceType.PHOTOLIBRARY
});
navigator.camera.getPicture(onSuccess, onFail, opts);
return true;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment