捕获一系列图像并将所有图像下载到文件夹

时间:2019-11-18 23:25:35

标签: javascript html

我有一个用于捕获一个图像的html网页的代码,可以通过右键单击它并将其另存为图片来保存。我不希望每次都按一次捕获来捕获一个图像。我希望它通过每次单击捕获来保存每个图像来捕获一系列图像,并可以选择删除过去的图片,并具有一个下载按钮来下载所有捕获的图片。

<!DOCTYPE html>

<html>
<head>
    <title>Scan Document</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
</head>
<body>
    <!-- Back Button -->
    <button onclick="window.history.back()">Back</button>
    <!-- Trigger canvas web API -->
    <div class=" = " video-wrap">
        <video id="video" playsinline autoplay></video>
    </div>
    <!-- Trigger canvas -->
    <div class="controller">
        <button id="snap">Capture</button>
    </div>

<!-- Webcam video snapshot -->
<canvas id="canvas" width="640" height="480"></canvas>

<script>
'use strict';

const video = document.getElementById('video');
const canvas= document.getElementById('canvas');
const snap = document.getElementById('snap');
const errorMsgElement = document.getElementById('spanErrorMsg');

const constraints = {
    audio: false,
    video:{
    width: 1280, height:720
         }

};

async function init() {
      try {
           const stream = await navigator.mediaDevices.getUserMedia(constraints);
           handleSuccess(stream);
      }
       catch(e){
             errorMsgElement.innerHTML = `navigator.getUserMedia.error:${e.toString()}`;
       }
}

//Success
function handleSuccess(stream){
    window.stream = stream;
    video.srcObject = stream;
    }
//Load init
init();
//Draw Image
var context = canvas.getContext('2d');
snap.addEventListener("click", function () {
    context.drawImage(video, 0, 0, 640, 480);
})

</script>
</body>
</html>

0 个答案:

没有答案