webapp - 只需点击一下即可通过手机主摄像头拍摄快照

时间:2017-09-30 16:15:24

标签: javascript android html5 web-applications android-camera

我真的希望它只拍一张快照并通过一次点击(一旦获得网站批准的摄像头访问)或仅打开链接就将其发送到服务器。我通过拍摄html5视频元素的视频流快照完成了这一点 - 参见示例。但是,质量是摄像头视频流快照质量。

我如何以合适的质量拍摄实际照片? 必须只能在android上运行。

btw:

<input id="myFileInput1" class="button" type="file" accept="image/*" capture>

不是一个选项,因为它需要点击,(选择凸轮),打开相机,拍照,批准图片

<body style="text-align: center;">
    <div style="display:none;">
        <video id="player" autoplay></video>
    </div>
    <div style="display: inline-block; margin: 0 auto;">
        <canvas id="canvas" width=853 height=1280></canvas>
    </div>

    <script>
        const player = document.getElementById('player');
        const canvas = document.getElementById('canvas');
        const context = canvas.getContext('2d');

        //8833ee7a5bcb161baa10970d674b8b003e769c40c452ed7ad7e31d235f0825c1

        const constraints = {
        video: { 
            optional: [{sourceId: "46884cf8fc3dc74cdefa932000380ae5d85b863a502428115bbdeb5d784be233"}]
        },
        };

        setTimeout(() => {
        context.drawImage(player, 0, 0, canvas.width, canvas.height);

        // Stop all video streams.
        player.srcObject.getVideoTracks().forEach(track => track.stop());
        }, 1500);


        navigator.mediaDevices.getUserMedia(constraints)
        .then((stream) => {
            // Attach the video stream to the video element and autoplay.
            player.srcObject = stream;
        });
    </script>

0 个答案:

没有答案