0

我正在尝试通过按钮使相机工作,但在下面的注释行中出现错误。我正在使用 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);
    }
4

2 回答 2

2

确保您首先获得了“设备就绪”事件。对于您对 getPicture() 的调用,请执行以下操作:

navigator.Camera.getPicture(onPhotoURISuccess, onFail, {
         quality: 50, 
         destinationType: navigator.camera.DestinationType.FILE_URI,
         sourceType: pictureSource
    });
于 2013-01-09T03:57:02.737 回答
0

我也在做这件事。如果您在谈论Android,则需要在真实设备上进行测试。无论您在 Eclipse 中在浏览器或模拟器上进行测试,都会出现 Camera not defined 错误。我猜是因为硬件问题。

于 2013-03-26T21:12:13.557 回答