我正在尝试通过按钮让相机正常工作,但我在下面的注释行中遇到错误。我使用的是Phonegap / Cordova(v2.1)提供的文档。任何帮助表示赞赏。
var pictureSource = navigator.Camera.PictureSourceType.CAMERA; // Cannot read PictureSourceType of undef
var destinationType = navigator.camera.DestinationType.FILE_URI;
function onPhotoURISuccess(imageURI) {
var placeImage = document.getElementById('placeImage');
placeImage.src = imageURI;
placeImage.style.display = 'block';
console.log(imageURI);
}
function getPhoto() {
navigator.Camera.getPicture(onPhotoURISuccess, onFail, { //I am getting an error for this line saying camera is not defined?
quality: 50,
destinationType: camera.destinationType.FILE_URI,
sourceType: pictureSource
});
}
function onFail(message) {
alert('Failed because: ' + message);
}
答案 0 :(得分:2)
确保您首先获得“deviceready”活动。要调用getPicture(),请执行以下操作:
navigator.Camera.getPicture(onPhotoURISuccess, onFail, {
quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: pictureSource
});
答案 1 :(得分:0)
我也正在研究这个问题。如果您在谈论Android,则需要在真实设备上进行测试。无论您在Eclipse中的浏览器或模拟器上进行测试,它都会为您提供Camera not defined error。我想这是因为硬件问题。