【问题标题】:phonegap I surrender to the camera phonegapphonegap 我向相机投降 phonegap
【发布时间】:2014-02-07 16:00:31
【问题描述】:

我用phonegap创建了一个新项目来利用相机,但没能让他让我拍照

我已经完成了http://docs.phonegap.com/es/3.1.0/cordova_camera_camera.md.html # C% C3% A1mara 的所有操作

但不是当我失败时,我没有收到任何错误。什么都不做

我的代码

<!DOCTYPE html>

<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />

        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />

        <title>Hello World</title>
    </head>
    <body>
       <button onclick="capturePhoto();">Capture Photo</button> <br>
    <button onclick="capturePhotoEdit();">Capture Editable Photo</button> <br>
    <button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
    <button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</button><br>
    <img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
    <img style="display:none;" id="largeImage" src="" />


    </body>
</html>

还有这个脚本

var pictureSource;  
    var destinationType;


    document.addEventListener("deviceready",onDeviceReady,false);


    function onDeviceReady() {
        pictureSource=navigator.camera.PictureSourceType;
        destinationType=navigator.camera.DestinationType;
    }


    function onPhotoDataSuccess(imageData) {

      var smallImage = document.getElementById('smallImage');


      smallImage.style.display = 'block';



      smallImage.src = "data:image/jpeg;base64," + imageData;
    }



    function onPhotoURISuccess(imageURI) {

      var largeImage = document.getElementById('largeImage');


      largeImage.style.display = 'block';


      largeImage.src = imageURI;
    }


    function capturePhoto() {
      // Take picture using device camera and retrieve image as base64-encoded string
      navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
        destinationType: destinationType.DATA_URL });
    }

    // A button will call this function
    //
    function capturePhotoEdit() {
      // Take picture using device camera, allow edit, and retrieve image as base64-encoded string
      navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true,
        destinationType: destinationType.DATA_URL });
    }

    // A button will call this function
    //
    function getPhoto(source) {
      // Retrieve image file location from specified source
      navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
        destinationType: destinationType.FILE_URI,
        sourceType: source });
    }

    // Called if something bad happens.
    //
    function onFail(message) {
      alert('Failed because: ' + message);
    }

我已经在 manifest.xml 中的 config.xml 中获得了许可,并且我添加了平台,但没有做任何事情。 帮助。非常感谢

【问题讨论】:

    标签: javascript android cordova phonegap-plugins


    【解决方案1】:

    你确定你安装了插件吗?

    你说你没有错误,是不是包括logcat?

    在您的 html 中,我没有看到 cordova.js 和您的 js 文件的包含。

    【讨论】:

    • 是的 QuickFix,我有 2 个脚本 我已经添加到命令行cordova插件添加org.apache.cordova.camera。并且表现完美,如果你给我一个完整的例子。不是我失败了。 alejo.go4@hotmail.com。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-30
    • 2016-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多