在官方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. Mac上pod install一直停住的解决办法

    pod install一直停住的解决办法 在/Users/XXX/.cocoapods/repos下 git clone https://github.com/CocoaPods/Specs.git ...

  2. 15分钟弄懂 const 和 #define

    什么是const ? 什么是#define? 他们有什么用? 他们有什么区别? 应该怎么用? 总结 1. 什么是const ? const是C/C++中的一个关键字(修饰符), const一般用来定义 ...

  3. hdu2025java字符题

    查找最大元素 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  4. Java基础知识强化之网络编程笔记08:TCP之客户端键盘录入服务器控制台输出

    1. 客户端: package cn.itcast_08; import java.io.BufferedReader; import java.io.BufferedWriter; import j ...

  5. use_virtual_func_without_pointer_left

    #include <oistream> using namespace std; class A { public: void foo() { func(); } virtual void ...

  6. 使用CSS的类名交集复合选择器

    首先先看一下基本定义: 复合选择器就是两个或多个基本选择器,通过不同方式连接而成的选择器,主要包括“交集”选择器.“并集”选择器.“后代”选择器. 交集选择器 “交集”复合选择器是由两个选择器直接连接 ...

  7. RedHat7上安装MariaDB

    编译安装MariaDB 下载MariaDB# wget http://mirrors.opencas.cn/mariadb//mariadb-10.1.8/source/mariadb-10.1.8. ...

  8. awk用法举例

    awk文本分割输出工具(按列输出工具) awk [options] ' PATTERN { action } ' file1, file2, ... 内置变量: FS:field separator, ...

  9. java Date日期去掉时分秒

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");String s = sdf.format(new Date() ...

  10. NLog 安装使用

    1:安装 Install-Package NLog.Config 或 通过Nuget 2:Log levels Trace 非常详细的信息,一般在开发时使用. Debug 比Trace稍微少一点一般不 ...