相机和图片资源类型没有定义Phonegap

Camera and PictureSourceType not defined Phonegap

本文关键字:定义 Phonegap 类型 图片资源 相机      更新时间:2023-09-26

我试图让相机从一个按钮工作,但我得到下面的注释行错误。我正在使用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);
    }

确保您首先有"deviceready"事件。对于getPicture()的调用,这样做:

navigator.Camera.getPicture(onPhotoURISuccess, onFail, {
         quality: 50, 
         destinationType: navigator.camera.DestinationType.FILE_URI,
         sourceType: pictureSource
    });

我也在做这件事。如果你谈论的是Android,你就需要在真正的设备上进行测试。无论您在Eclipse中的浏览器或模拟器上测试,它都会给您Camera not defined错误。我猜是硬件问题。