在官方3.0 提供的摄像机操作例子是不成功的,因为该例子没有说明摄像机操作需要添加Plugin。

添加插件方法(安装cordova3.0时必须使用官方命令行方式,通过nodejs安装,且装上了git):

$ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git 

$ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture.git 

$ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-media.git

最后附上官方操作代码:

<!DOCTYPE html>

<html>

  <head>

    <title>Capture Photo</title>

<script type="text/javascript" charset="utf-8" src="cordova-3.0.0.js"></script>

    <script type="text/javascript" charset="utf-8">

var pictureSource;   // picture source

    var destinationType; // sets the format of returned value

// Wait for device API libraries to load

    //

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

// device APIs are available

    //

    function onDeviceReady() {

        pictureSource=navigator.camera.PictureSourceType;

        destinationType=navigator.camera.DestinationType;

    }

// Called when a photo is successfully retrieved

    //

    function onPhotoDataSuccess(imageData) {

      // Uncomment to view the base64-encoded image data

      // console.log(imageData);

// Get image handle

      //

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

// Unhide image elements

      //

      smallImage.style.display = 'block';

// Show the captured photo

      // The inline CSS rules are used to resize the image

      //

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

    }

// Called when a photo is successfully retrieved

    //

    function onPhotoURISuccess(imageURI) {

      // Uncomment to view the image file URI

      // console.log(imageURI);

// Get image handle

      //

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

// Unhide image elements

      //

      largeImage.style.display = 'block';

// Show the captured photo

      // The inline CSS rules are used to resize the image

      //

      largeImage.src = imageURI;

    }

// A button will call this function

    //

    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);

    }

</script>

  </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>

Phonegap 3.0 拍照 出错的说明的更多相关文章

  1. phonegap + xcode5.0.2 配置开发环境

    phonegap官网:  http://phonegap.com/ 第一部:安装nodejs 安装地址:http://nodejs.org/ 安装phoneGap 官网下载http://phonega ...

  2. Phonegap 3.0 设置APP是否全屏

    Phonegap 3.0 默认是全屏,如需要取消全屏,可手动修改config, 在APP/res/xml/config.xml文件可设置preference: <?xml version='1. ...

  3. paip.vs2010 或.net 4.0安装出错解决大法.

    paip.vs2010 或.net 4.0安装出错解决大法. 作者Attilax ,  EMAIL:1466519819@qq.com  来源:attilax的专栏 地址:http://blog.cs ...

  4. PhoneGap 3.0 安装

    PhoneGap 3.0  已经出来有一段时间了.3.0 提供了使用Node.js 安装,使用命令行创建.编译.运行项目.也就是可以抛弃eclipse,完全使用命令.记事本开发phonegap 项目了 ...

  5. 关于用phonegap 3.0+ 打包后sencha touch按钮点击切换动画延迟接近一秒的以及界面闪烁的解决方案

    android的webview对硬件加速的支持貌似很不理想,在开启硬件加速的情况下,css3这些需要调用硬件加速的样式会大幅拖慢html5的webapp,在htc的部分手机上还会因开启硬件加速而导致闪 ...

  6. 使用phonegap + appframework2.0框架

    1.页面切换动画结束时卡(禁用动画) 2.搜索或导航标签需要固定(标签选择器动态修改高度) 3.pancel容器默认生成的时候内容不放 通过动态的的$("").empty().ht ...

  7. phonegap platform add ios 出错的问题

    在Mac上新安装的Phonegap,版本3.3-0.18.0. 本来创建项目后按教程: http://docs.phonegap.com/en/edge/guide_platforms_ios_ind ...

  8. PhoneGap 3.0 官方 安装 方法

    为使用最新版本PhoneGap ,决定使用官方提供的方法安装一次. 官方提供方法有些地方没有提到,因此这里记录完整的安装过程: 0.下载java sdk 1.6以上版本 1.下载Android Dev ...

  9. Phonegap 3.0 获取当前地址位置

    新版本的cordova 3.0 中,使用官方的示例可直接获取当前手机的地理位置,前提是手机开启了gps,或可联网. 获取到的是经纬度坐标值等信息,可通过google api 实现通过经纬度获取当前地理 ...

随机推荐

  1. Myapplication的作用与理解

    1.前沿在设置里面,对应于某一个应用,虽然没有启动,但是上面有一个终止按钮,说明这个应用时启动的,只是里面没有Activity,所以说使用android退出把一个应用退出,实际上他所对应的Applic ...

  2. Apache Kafka: Next Generation Distributed Messaging System---reference

    Introduction Apache Kafka is a distributed publish-subscribe messaging system. It was originally dev ...

  3. xmemcached user guide --存档

    XMemcached Introduction XMemcached is a new java memcached client. Maybe you don't know "memcac ...

  4. PureMVC(JS版)源码解析(十一):Model类

          这篇博文讲PureMVC三个核心类——Model类.Model类的构造函数及工厂函数[即getInstance()方法]和View类.Controller类是一样的,这里就不重复讲解了,只 ...

  5. cellspacing cellpadding

    <table border="1" cellspacing="300" cellpadding="100">    <tr ...

  6. HDU2028JAVA

    Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  7. vs2010 Express 下载连接

    记录: vs2010  Express 下载连接 正式下载链接: http://download.microsoft.com/download/5/C/1/5C156922-CA10-49D8-B7E ...

  8. wiki 使用笔记

    Wiki 安装:Linux(Redhat EL5.3)下安装配置MediaWiki wiki配置: 配置文件:DefaultSettings.php  //权限等配置 左边导航条:/wiki/inde ...

  9. Spring声明式事务(xml配置事务方式)

    Spring声明式事务(xml配置事务方式) >>>>>>>>>>>>>>>>>>>& ...

  10. Oracle 特殊字符模糊查询的方法

    最近在写DAO层的时候,遇到一个问题,就是使用like进行模糊查询时,输入下划线,无法精确查到数据,而是返回所有的数据. 这让我很好奇,百度之后才发现,原来是因为有些特殊字符需要进行转义才可以进行查询 ...