温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

HTML 5调用摄像头并进行拍照 (测试火狐能行)

发布时间:2020-04-06 01:18:18 来源:网络 阅读:1710 作者:曦羽 栏目:开发技术
  1. 参考网址

    http://blog.csdn.net/guoquanyou/article/details/51802849


    http://blog.csdn.net/dengmingrun/article/details/17374273(未测试)

<!DOCTYPE html>  <html lang="en">  <head>  <meta charset="UTF-8">  <title>Document</title>  <style>  video {      border: 1px solid #ccc;      display: block;      margin: 0 0 20px 0;      float:left;  }  #canvas {      margin-top: 20px;      border: 1px solid #ccc;      display: block;  }  </style>  </head>  <body>      <video id="video" width="500" height="400" autoplay></video>      <canvas id="canvas" width="500" height="400"></canvas>      <button id="snap">拍照</button>      <script type="text/javascript">          var context = canvas.getContext("2d");          //当DOM树构建完成的时候就会执行DOMContentLoaded事件          window.addEventListener("DOMContentLoaded", function() {              //获得Canvas对象              var canvas = document.getElementById("canvas");              //获得video摄像头区域              var video = document.getElementById("video");              var videoObj = {                  "video" : true              };              var errBack = function(error) {                  console.log("Video capture error: ", error.code);              };              //获得摄像头并显示到video区域              if (navigator.getUserMedia) { // Standard                  navigator.getUserMedia(videoObj, function(stream) {                      video.src = stream;                      video.play();                  }, errBack);              } else if (navigator.webkitGetUserMedia) { // WebKit-prefixed                  navigator.webkitGetUserMedia(videoObj, function(stream) {                      video.src = window.webkitURL.createObjectURL(stream);                      video.play();                  }, errBack);              } else if (navigator.mozGetUserMedia) { // Firefox-prefixed                  navigator.mozGetUserMedia(videoObj, function(stream) {                      video.src = window.URL.createObjectURL(stream);                      video.play();                  }, errBack);              }          }, false);          // 触发拍照动作          document.getElementById("snap").addEventListener("click", function() {              context.drawImage(video, 0, 0, 640, 480);          });      </script>  </body>  </html>  


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI