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页面如何调用摄像头代码分享的详细内容,更多请关注双恒网络其它相关文章!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。