Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
[HTML] Bilder einer Webcam speichern
#5
<!DOCTYPE html>
<html>
<head>
    <title>Webcam Capture</title>
</head>
<body>
    <video id="video" width="640" height="480" autoplay></video>
    <script>
        const video = document.getElementById('video');
        const downloadFolder = 'download-folder'; // Fest hinterlegter Downloadordner

        // Zugriff auf die Webcam
        navigator.mediaDevices.getUserMedia({ video: true })
            .then(function (stream) {
                video.srcObject = stream;
            })
            .catch(function (error) {
                console.error('Error accessing webcam: ', error);
            });

        // Funktion zum Aufnehmen und automatischen Speichern des Bildes
        function takeSnapshotAndSave() {
            const canvas = document.createElement('canvas');
            canvas.width = video.videoWidth;
            canvas.height = video.videoHeight;
            const context = canvas.getContext('2d');

            // Nehme ein Bild vom Video auf und speichere es im Canvas
            context.drawImage(video, 0, 0, canvas.width, canvas.height);

            // Lade das Bild herunter
            const fileName = 'snapshot_' + Date.now() + '.jpeg';
            const a = document.createElement('a');
            a.href = canvas.toDataURL('image/jpeg'); // Das Bild als Data-URL im JPEG-Format
            a.download = `${downloadFolder}/${fileName}`; // Pfad und Dateiname
            a.click(); // Löst den automatischen Download des Bildes aus
        }

        // Starte den automatischen Speichern alle Sekunde
        setInterval(takeSnapshotAndSave, 1000); // 1000 Millisekunden = 1 Sekunde
    </script>
</body>
</html>
Zitieren Return to top


Nachrichten in diesem Thema
Bilder einer Webcam speichern - von Joopi - 04-08-2023, 04:24
RE: Bilder einer Webcam speichern - von Joopi - 04-08-2023, 04:30
RE: Bilder einer Webcam speichern - von Joopi - 04-08-2023, 04:34
RE: Bilder einer Webcam speichern - von Joopi - 04-08-2023, 04:38
RE: Bilder einer Webcam speichern - von Joopi - 04-08-2023, 04:51

Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste