在官方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. iOS AvPlayer AvAudioPlayer音频的后台播放问题

    iOS 4开始引入的multitask,我们可以实现像ipod程序那样在后台播放音频了.如果音频操作是用苹果官方的AVFoundation.framework实现,像用AvAudioPlayer,Av ...

  2. Linux 性能优化之 IO 子系统 系列 图

    http://blog.sina.com.cn/s/articlelist_1029388674_11_1.html Linux 性能优化之 IO 子系统(一) 本文介绍了对 Linux IO 子系统 ...

  3. 常用命令-eval简析

    www.2cto.com   1. 工作原理及用法   用法:eval command-line 原理:eval主要用在对参数的特殊处理上面的,一般的命令行,shell处理参数就只执行一遍,像转义和变 ...

  4. HDU2054JAVA

    (包括2016级新生)除了校赛,还有什么途径可以申请加入ACM校队? A == B ? Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: ...

  5. linux中的网络通信指令 分类: 学习笔记 linux ubuntu 2015-07-06 16:02 134人阅读 评论(0) 收藏

    1.write write命令通信是一对一的通信,即两个人之间的通信,如上图. 效果图 用法:write <用户名> 2.wall wall指令可将信息发送给每位同意接收公众信息的终端机用 ...

  6. CentOS Linux修改系统时区

    ln –sf /usr/share/zoneinfo/Hongkong /etc/localtime

  7. Top 12 Best Free Network Monitoring Tools (12种免费网络监控工具)

    1) Fiddler Fiddler(几乎)是适用于任何平台和任何操作系统的最好的免费网络工具,并提供了一些广受欢迎的关键特性.如:性能测试.捕捉记录HTTP/HTTPs请求响应.进行web调试等很多 ...

  8. vs2010 “发生生成错误,运行上次的成功运行的程序”怎么改回不运行。

    当程序出现错误时,会出现下面对话框: 如果选择"是",并且勾选了"不再显示此对话框",对你以后的操作时非常麻烦的. 许多同学想再次调出次窗口,不知道怎么操作,操 ...

  9. PHP 单一入口

    单一入口概述 单一入口的应用程序就是说用一个文件处理所有的HTTP请求,例如不管是列表页还是文章页,都是从浏览器访问index.php文件,这个文件就是这个应用程序的单一入口. 打个比方,大家都要上W ...

  10. C++的函数重载 转

    ——每个现象后面都隐藏一个本质,关键在于我们是否去挖掘 写在前面: 函数重载的重要性不言而明,但是你知道C++中函数重载是如何实现的呢(虽然本文谈的是C++中函数重载的实现,但我想其它语言也是类似的) ...