您好,登錄后才能下訂單哦!
參考網址
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>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。