码迷,mamicode.com
首页 > Windows程序 > 详细

前端启动摄像头的API

时间:2018-03-04 13:02:13      阅读:471      评论:0      收藏:0      [点我收藏+]

标签:video   canvas   ice   on()   list   doc   event   utf-8   dev   

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<video id="video" width="640" height="480" autoplay></video>
<button id="snap">Snap Photo</button>
<canvas id="canvas" width="640" height="480"></canvas>
<script type="text/javascript">
window.onload = function(){
var canvas = document.getElementById(‘canvas‘);
var context = canvas.getContext(‘2d‘);
var video = document.getElementById(‘video‘);
// Get access to the camera!
if(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
// Not adding `{ audio: true }` since we only want video now
navigator.mediaDevices.getUserMedia({ video: true }).then(function(stream) {
video.src = window.URL.createObjectURL(stream);
video.play();
});
}

document.getElementById("snap").addEventListener("click", function() {
context.drawImage(video, 0, 0, 640, 480);
});
}
</script>
</body>
</html>

前端启动摄像头的API

标签:video   canvas   ice   on()   list   doc   event   utf-8   dev   

原文地址:https://www.cnblogs.com/boonook/p/8504251.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!