
Phonegap 1.8 attempt to get camera working
By: a guest on
Jun 14th, 2012 | syntax:
JavaScript | size: 1.04 KB | hits: 32 | expires: Never
var pictureSource; // picture source
var destinationType; // sets the format of returned value
document.addEventListener("deviceready",onDeviceReady,false);
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
function onPhotoDataSuccess(imageData) {
// navigator.notification.alert("win");
var smallImage = document.getElementById('smallImage');
// smallImage.style.display = 'block';
smallImage.src = "data:image/jpeg;base64," + imageData;
draw(smallImage);
}
function capturePhoto() {
if (navigator.camera) {
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 25, destinationType: destinationType.DATA_URL });
} else {
console.log("phonegap camera not available");
}
}
function onFail(message) {
//navigator.notification.alert("fail");
alert('Failed because: ' + message);
}