gdyyy 发表于 2014-11-26 09:33:41

为什么我在phonegap android拍照,执行时出现不能加载getPicture

我在phonegap android拍照,执行时出现不能加载getPicture
代码是:
<script type="text/javascript" charset="utf-8">

    var pictureSource;//设定图片来源
    var destinationType; //选择返回数据的格式

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

    // Cordova准备好了可以使用了
    function onDeviceReady() {
      pictureSource=navigator.camera.PictureSourceType;
      destinationType=navigator.camera.DestinationType;
    }

    function onPhotoDataSuccess(imageData) {
      // base64 encoded image data
      var smallImage = document.getElementById('smallImage');

      smallImage.style.display = 'block';
      //在使用base64编码的时候需要使用这样的前缀
      smallImage.src = "data:image/jpeg;base64," + imageData;
    }

    // Called when a photo is successfully retrieved
    //
    function onPhotoURISuccess(imageURI) {
      // image file URI   
      var largeImage = document.getElementById('largeImage');
      largeImage.style.display = 'block';
      //使用image file URI 直接赋值就可以了
      largeImage.src = imageURI;
    }

    // 第一个按钮调用函数
    function capturePhoto() {
      navigator.camera.getPicture(onPhotoDataSuccess, onFail, {quality: 50});
    }

    //第二个按钮调用的函数
    function capturePhotoEdit() {
      navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true});
    }

    //第三/四个按钮调用的函数
    function getPhoto(source) {
      // Retrieve image file location from specified source
      navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, destinationType: destinationType.FILE_URI, sourceType: source });
    }

    function onFail(message) {
      alert('Failed because: ' + message);
    }

    </script>
<a href="#" onclick="capturePhoto();" data-role="button" > 拍照 </a>

wjwcq 发表于 2015-1-18 00:25:11

有没有引入cordova.js?

parishe 发表于 2015-5-26 10:48:48

向前辈学习中 顶起

xpbasic 发表于 2015-5-26 10:39:48

又可以学习了,好开心
页: [1]
查看完整版本: 为什么我在phonegap android拍照,执行时出现不能加载getPicture