想着研究下HTML5实现调用摄像头的一些方法。看了一下html5文档,主要是使用html5的getUserMedia()API,写一个例子来记录具体的使用方法。
<html>
<body>
<!-- 用于展示摄像头视频流 -->
<video id="video" autoplay style="width: 480px;height: 320px"></video>
<div>
<button id="capture" onclick="handleClickCapture()">拍照</button>
</div>
<!-- 展示拍摄的照片 -->
<canvas id="canvas" width="480" height="320"></canvas>
<script>
var video = document.getElementById('video');
var capture = document.getElementById('capture');
var ctx = document.getElementById('canvas').getContext('2d');
/**
* 调用用户媒体设备
* @param constraints 配置信息
* @param success 成功回调函数
* @param error 失败回调函数
*/
function getUserMediaToPhoto(constraints,success,error) {
if(na