拍照

拍照


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <video id="video" autoplay="" style='width:200px;height:300px'></video>

    <button id='picture'>PICTURE</button>

    <canvas id="canvas" width="400" height="300"></canvas>

    <script>
        var video = document.getElementById("video");
        var context = canvas.getContext("2d")
        var errocb = function () {
            console.log('sth wrong!');
        }
            navigator.mediaDevices.getUserMedia({
                    "video": true
                }).then(function (stream) {
                    video.src = window.webkitURL.createObjectURL(stream);
                    video.play();
                }).catch(errocb);
        
        document.getElementById("picture").addEventListener("click", function () {
            context.drawImage(video, 0, 0, 400, 300);
        });
    </script>
</body>
</html>

posted on 2017-12-26 18:00  ouruixi  阅读(151)  评论(0)    收藏  举报

导航