首页 > 代码库 > h5页面调用摄像头(简易版)
h5页面调用摄像头(简易版)
<input type="button" value="OpenVideo" id="btnOpenVideo" /> <input type="button" value="TakePicture" id="btnTakePicture" /> <input type="button" value="CloseVideo" id="btnCloseVideo" /> <br /> <video style="width:500px;height:500px;border:1px solid #000000;" id="videoTest"></video> <canvas style="width:500px;height:500px;border:1px solid #000000;" id="canvasTest"></canvas> <script type="text/javascript"> window.onload = function () { let btnOpenVideo = document.getElementById(‘btnOpenVideo‘); let btnTakePicture = document.getElementById(‘btnTakePicture‘); let btnCloseVideo = document.getElementById(‘btnCloseVideo‘); let video = document.getElementById(‘videoTest‘); let canvas = document.getElementById(‘canvasTest‘).getContext(‘2d‘); btnOpenVideo.onclick = function () { window.navigator.getUserMedia({ video: true/*视频/摄像头*/
/*audio:true*//*音频/麦克风*/ }, function (param) { video.src = window.URL.createObjectURL(param);/*设置video控件路径,实时显示摄像头的图像*/ btnCloseVideo.onclick = function () {/*关闭摄像头*/ if (param.getTracks())/*Chrome*/ param.getTracks()[0].stop(); else param.stop(); }; btnTakePicture.onclick = function () {/*拍照*/ canvas.drawImage(document.getElementById(‘videoTest‘), 0, 0, 500, 500);/*将拍摄的照片画到canvas中*/ }; }, function (err) { alert(err); }); }; }; </script>
h5页面调用摄像头(简易版)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。