【问题标题】:Camera and PictureSourceType not defined PhonegapCamera 和 PictureSourceType 未定义 Phonegap
【发布时间】:2013-01-08 21:43:14
【问题描述】:

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

【问题讨论】:

  • 你能读懂destinationType吗?您是否在脚本中包含了 cordova.js?
  • 嗨 cggaurav,我的脚本中有这个。 我没有包含 onDeviceReady 函数,因为我已经在测试我的数据库了前。它是否正确?我应该先到达目的地才能拍照吗?
  • docs.phonegap.com/en/2.0.0/cordova_camera_camera.md.html,应该是 navigator.camera 而不是 navigator.Camera?
  • 我在 Eclipse 中尝试过,但仍然遇到同样的错误。不过感谢您的错字。
  • 仅用这段 javascript 很难弄清楚可能有什么问题,最好运行 docs.phonegap.com/en/2.0.0/cordova_camera_camera.md.html 中的快速示例

标签: javascript cordova camera


【解决方案1】:

确保您首先获得了“deviceready”事件。要调用 getPicture(),请执行以下操作:

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

【讨论】:

  • 谢谢西蒙,我使用这种方法仍然得到错误(未定义)。我现在无法处理我的代码,但稍后会再试一次。请参阅我对上述内容的最后评论。也许你可以阐明为什么它现在可以工作,没有那条线。我现在正在获取成功功能,并且图像路径正在记录到控制台,所以我想现在使用它足够安全吗?
  • 我可能应该补充一点,错误仍然记录在 Eclipse 的控制台中。尽管如此,我可以用相机拍照,在我的 html 中显示,在控制台中调用成功函数和日志路径。我通过 Eclipse 在手机上对此进行了测试。
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 2014-05-15
    • 1970-01-01
    • 2014-02-07
    • 2013-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-12
    相关资源
    最近更新 更多