Created
January 27, 2012 19:43
-
-
Save bhuber/1690549 to your computer and use it in GitHub Desktop.
Phonegap Camera Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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