html5中拍照camera_第1页
html5中拍照camera_第2页
html5中拍照camera_第3页
html5中拍照camera_第4页
html5中拍照camera_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、html5 中拍照 camera方法:getCamera: 获取摄像头管理对象 对象:Camera: 摄像头对象CameraOption: JSON 对象,调用摄像头的参数PopPosition: JSON 对象,弹出拍照或摄像界面指示位置 回调方法:CameraSuccessCallback: 调用摄像头操作成功回调 CameraErrorCallback: 摄像头操作失败回调 权限: 功能模块( permissions)/ ."permissions":/ ."Camera": "description": " 摄像头

2、" getCamera 获取摄像头管理对象Camera plus.camera.getCamera( index );说明: 获取需要操作的摄像头对象, 如果要进行拍照或摄像操作, 需先通过此方法获取摄像头对象。 参数:index: ( Number ) 可选 要获取摄像头的索引值指定要获取摄像头的索引值, 1 表示主摄像头, 2 表示辅摄像头。如果没有设置则使用系统 默认主摄像头。返回值:Camera : 摄像头对象平台支持:Android - 2.2+ ( 支持 ) iOS - 4.3+ ( 支持) 示例:<!DOCTYPE html><html><

3、head><meta charset="utf-8"><title>Camera Example</title><script type="text/javascript">/ 扩展 API 加载完毕后调用 onPlusReady 回调函数 document.addEventListener( "plusready", onPlusReady, false ); var r = null;/ 扩展 API 加载完毕,现在可以正常调用扩展 API function onPlusRea

4、dy() / 获取设备默认的摄像头对象var cmr = plus.camera.getCamera();/ </script></head><body></body></html>Camera摄像头对象interface Camera readonly attribute String supportedImageResolutions; readonly attribute String supportedVideoResolutions;readonly attribute String supportedImageFormat

5、s; readonly attribute String supportedVideoFormats;function void captureImage( successCB, errorCB, option ); function void startVideoCapture( successCB, errorCB, option ); function void stopVideoCapture();属性:supportedImageResolutions: 字符串数组,摄像头支持的拍照分辨率 supportedVideoResolutions: 字符串数组,摄像头支持的摄像分辨率 su

6、pportedImageFormats: 字符串数组,摄像头支持的拍照文件格式supportedVideoFormats: 字符串数组,摄像头支持的摄像文件格式 方法:captureImage: 进行拍照操作startVideoCapture: 调用摄像头进行摄像操作 stopVideoCapture: 结束摄像操作supportedImageResolutions字符串数组, 说明:摄像头支持的拍照分辨率Array 类型只读属性属性类型为 符串形式“ 平台支持:String ,若不支持此属性则返回空数组对象。摄像头支持的拍照图片分辨率字 WIDTH*Height ”,如“ 400*800 ”

7、;如果支持任意自定义分辨率则“ * ”。Android ( 支持 )iOS (不支持 ): 返回空数组对象 示例:<!DOCTYPE html><html><head><meta charset="utf-8"><title>Camera Example</title><script type="text/javascript">/ 扩展 API 加载完毕后调用 onPlusReady 回调函数 document.addEventListener( "plusr

8、eady", onPlusReady, false );/ 扩展 API 加载完毕,现在可以正常调用扩展 APIfunction onPlusReady() var cmr = plus.camera.getCamera();alert( "Camera supperted image resolutions: " + cmr.supportedImageResolutions ); </script></head><body></body></html> supportedVideoResolution

9、s字符串数组, 说明:摄像头支持的摄像分辨率Array 类型只读属性String ,若不支持此属性则返回空数组对象。摄像头支持的视频分辨率字符串”。属性类型为形式为“ WIDTH*Height ”,如“ 400*800 ”;如果支持任意自定义分辨率则“ 平台支持:Android ( 支持 )iOS (不支持 ): 返回空数组对象 示例:<!DOCTYPE html><html><head><meta charset="utf-8"><title>Camera Example</title><scr

10、ipt type="text/javascript">/ 扩展 API 加载完毕后调用 onPlusReady 回调函数 document.addEventListener( "plusready", onPlusReady, false );/ 扩展 API 加载完毕,现在可以正常调用扩展 APIfunction onPlusReady() var cmr = plus.camera.getCamera();alert( "Camera supperted image resolutions: " + cmr.supporte

11、dImageResolutions ); </script></head><body></body></html>supportedImageFormats字符串数组, 说明:摄像头支持的拍照文件格式Array 类型只读属性属性类型为 串形式为文件格式后缀名,如“ 平台支持:String ,若不支持此属性则返回空数组对象。摄像头支持的图片文件格式字符”a”a I”jpg”、“png”、“bmp”。Android ( 支持 )iOS (不支持 ): 返回空数组对象 示例:<!DOCTYPE html><html>

12、<head><meta charset="utf-8"><title>Camera Example</title><script type="text/javascript">/ 扩展 API 加载完毕后调用 onPlusReady 回调函数 document.addEventListener( "plusready", onPlusReady, false );/ 扩展 API 加载完毕,现在可以正常调用扩展 API function onPlusReady() var c

13、mr = plus.camera.getCamera();alert( "Camera supperted image formats: " + cmr.supportedImageFormats ); </script></head><body></body></html>supportedVideoFormats字符串数组, 说明:摄像头支持的摄像文件格式Array 类型只读属性属性类型为 串形式为文件格式后缀名,如“ 平台支持:String ,若不支持此属性则返回空数组对象。摄像头支持的视频文件格式字符C”“

14、A ”“”3gp”、“ mp4”、“ avi”。Android ( 支持 )iOS (不支持 ): 返回空数组对象 示例:<!DOCTYPE html><html><head><meta charset="utf-8"><title>Camera Example</title><script type="text/javascript">/ 扩展 API 加载完毕后调用 onPlusReady 回调函数 document.addEventListener( "p

15、lusready", onPlusReady, false );/ 扩展 API 加载完毕,现在可以正常调用扩展 API function onPlusReady() var cmr = plus.camera.getCamera();alert( "Camera supperted video formats: " + cmr.supportedVideoFormats ); </script></head><body></body></html> captureImage进行拍照操作cmr.captu

16、reImage( successCB, errorCB, option );说明: 摄像头资源为独占资源,如果其它程序或页面已经占用摄像头,再次操作则失败。 拍照操 作成功将通过 successCB 返回拍照获取的图片路径。 可通过 option 设置摄像头的各种属性 参数。参数:successCB: ( CameraSuccessCallback ) 必选 拍照操作成功的回调函数 errorCB: ( CameraErrorCallback ) 可选 拍照操作失败的回调函数 option: ( CameraOption ) 必选 摄像头拍照参数返回值: void : 无 平台支持:Andro

17、id - 2.2+ ( 支持 ) iOS - 4.3+ ( 支持) 示例:<!DOCTYPE html><html><head><meta charset="utf-8"><title>Camera Example</title><script type="text/javascript">/ 扩展 API 加载完毕后调用 onPlusReady 回调函数 document.addEventListener( "plusready", onPlusRe

18、ady, false ); / 扩展 API 加载完毕,现在可以正常调用扩展 API function onPlusReady() console.log("plusready");/ 拍照function captureImage()var cmr = plus.camera.getCamera();var res = cmr.supportedImageResolutions0;var fmt = cmr.supportedImageFormats0; console.log("Resolution: "+res+", Format: &q

19、uot;+fmt); cmr.captureImage( function( path ) alert( "Capture image success: " + path );, function( error ) alert( "Capture image failed: " + error.message ); ,resolution:res,format:fmt); </script> </head> <body><button onclick="captureImage()">

20、拍照 </button> </body></html> startVideoCapture调用摄像头进行摄像操作cmr.startVideoCapture( successCB, errorCB, option );说明:摄像头资源为独占资源,如果其它程序或页面已经占用摄像头,再次操作则失败。 拍照操 作成功将通过 successCB 返回摄像获取的视频文件路径。可通过 option 设置摄像头的各种属性参数。参数:successCB: ( CameraSuccessCallback ) 必选 摄像操作成功的回调函数 errorCB: ( CameraErr

21、orCallback ) 可选 拍摄像操作失败的回调函数 option: ( CameraOption ) 必选 摄像头拍照参数返回值: void : 无 平台支持:Android - 2.2+ ( 支持) iOS - 4.3+ ( 支持) 示例:<!DOCTYPE html> <html><head><meta charset="utf-8"><title>Camera Example</title><script type="text/javascript">/ 扩展

22、 API 加载完毕后调用 onPlusReady 回调函数 document.addEventListener( "plusready", onPlusReady, false );/ 扩展 API 加载完毕,现在可以正常调用扩展 API function onPlusReady() console.log("plusready");/ 摄像function videoCapture()var cmr = plus.camera.getCamera();var res = cmr.supportedVideoResolutions0;var fmt =

23、cmr.supportedVideoFormats0; console.log("Resolution: "+res+", Format: "+fmt); cmr.startVideoCapture( function( path ) alert( "Capture video success: " + path );, function( error ) alert( "Capture video failed: " + error.message );, resolution:res,format:fmt);&

24、lt;/script></head><body><button onclick="videoCapture()"> 摄像 </button> </body></html> stopVideoCapture结束摄像操作cmr.stopVideoCapture();说明: 开始调用摄像头进行摄像操作后, 可在后台结束摄像操作, 与用户在界面结束操作效果一致。 摄像操作成功将通过 startVideoCapture 函数中的 successCB 返回拍照获取的图片路径。 用 户如果没有进行摄像操作关闭摄

25、像头页面则调用失败回调函数。参数: 返回值: void : 无 平台支持:Android - ALL ( 不支持 ): 暂不支持调用此 API 停止摄像,需要手动操作停止。 iOS - ALL ( 不支持 ): 暂不支持调用此 API 停止摄像,需要手动操作停止。 示例:<!DOCTYPE html><html><head><meta charset="utf-8"><title>Camera Example</title><script type="text/javascript&qu

26、ot;>/ 扩展 API 加载完毕后调用 onPlusReady 回调函数 document.addEventListener( "plusready", onPlusReady, false );/ 扩展 API 加载完毕,现在可以正常调用扩展 API function onPlusReady() console.log("plusready");var cmr=null;/ 摄像function videoCapture()cmr = plus.camera.getCamera();var res = cmr.supportedVideoRes

27、olutions0;var fmt = cmr.supportedVideoFormats0; console.log("Resolution: "+res+", Format: "+fmt); cmr.startVideoCapture( nction( path ) alert( "Capture video success: " + path );, function( error ) alert( "Capture video failed: " + error.message );,resolution:

28、res,format:fmt);/ 拍摄 10s 后自动完成 setTimeout( stopCapture, 10000 );/ 停止摄像 function stopCapture() console.log("stopCapture"); cmr.stopVideoCapture();</script></head><body><button onclick="videoCapture()"> 摄像 </button><br/> <button onclick="

29、stopCapture()"> 停止摄像 </button> </body></html>CameraOptionJSON 对象,调用摄像头的参数interface CameraOption attribute String filename; attribute String format; attribute String index; attribute PopPosition popover;属性:filename: (String 类型 )拍照或摄像文件保存的路径可设置具体文件名(如 "_doc/camera/a.jpg&

30、quot; );也可只设置路径,以 "/" 结尾则表明是路径(如"_doc/camera/")。如未设置文件名称或设置的文件名冲突则文件名由程序程序自动生成。format: (String 类型 )拍照或摄像的文件格式可通过 Camera 对象的 supportedImageFormats 或 supportedVideoFormats 获取,如果设置的参 数无效则使用系统默认值。index: (String 类型 )拍照或摄像默认使用的摄像头1 表示主摄像头, 2 表示辅摄像头。拍照或摄像界面默认使用的摄像头编号, 平台支持Android - 2.2+ ( 不支持 ): 暂不支持设置摄像头,忽略此属性值iOS - 4.3+ (支持 )popover: (PopPosition 类型 )拍照或摄像界面弹出指示区域对于大屏幕设备如iP ad,拍照或摄像界面为弹出窗口,此时可通过此参数设置弹出窗口位置,其为 JSON 对象,格式如 top:"10px",left:"10px",width:"200px",height:"200px" ,默认弹出位 置为屏幕居中。平台支持Android - ALL ( 不支持 ): 暂不支持设置摄像头,忽略此属性值iOS - 5.

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论