标签:摄像头 wim onclick var load console name body str
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>摄像头拍照</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <video id=‘video‘></video> <canvas id="canvas"></canvas> <img id="image"> </head> <body> <script> var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia; if (getUserMedia) { navigator.getUserMedia({ audio: true, video: { width: 90, height: 120 } }, function(stream) { var video = document.querySelector(‘video‘); video.src = window.URL.createObjectURL(stream); video.onloadedmetadata = function(e) { video.play(); }; }, function(err) { console.log(err); } ); } document.getElementById(‘video‘).onclick = function(){ var canvas = document.getElementById("canvas"); var context = canvas.getContext("2d"); var video = document.getElementById("video"); context.drawImage(video, 0, 0, 90, 120); document.getElementById(‘image‘).src = canvas.toDataURL("image/png"); } </script> </body> </html>
标签:摄像头 wim onclick var load console name body str
原文地址:https://www.cnblogs.com/huangtonghui/p/9397424.html