溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

HTML 5調(diào)用攝像頭并進行拍照 (測試火狐能行)

發(fā)布時間:2020-04-06 01:18:18 來源:網(wǎng)絡(luò) 閱讀:1706 作者:曦羽 欄目:開發(fā)技術(shù)
  1. 參考網(wǎng)址

    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樹構(gòu)建完成的時候就會執(zhí)行DOMContentLoaded事件          window.addEventListener("DOMContentLoaded", function() {              //獲得Canvas對象              var canvas = document.getElementById("canvas");              //獲得video攝像頭區(qū)域              var video = document.getElementById("video");              var videoObj = {                  "video" : true              };              var errBack = function(error) {                  console.log("Video capture error: ", error.code);              };              //獲得攝像頭并顯示到video區(qū)域              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);          // 觸發(fā)拍照動作          document.getElementById("snap").addEventListener("click", function() {              context.drawImage(video, 0, 0, 640, 480);          });      </script>  </body>  </html>  


向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI