Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating text #397

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kamera App</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
}
#cameraContainer {
text-align: center;
}
video, canvas {
width: 100%;
max-width: 400px;
border: 1px solid #ccc;
border-radius: 8px;
}
button {
margin-top: 10px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
border: none;
background-color: #007bff;
color: white;
border-radius: 4px;
}
button:disabled {
background-color: #ccc;
}
</style>
</head>
<body>
<div id="cameraContainer">
<video id="video" autoplay></video>
<canvas id="canvas" style="display: none;"></canvas>
<button id="snap">Foto aufnehmen</button>
</div>

<script>
const video = document.getElementById('video');
const canvas = document.getElementById('canvas');
const snapButton = document.getElementById('snap');

// Zugriff auf die Kamera anfordern
async function startCamera() {
try {
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
video.srcObject = stream;
} catch (error) {
console.error('Fehler beim Zugriff auf die Kamera:', error);
alert('Kamera konnte nicht aktiviert werden.');
}
}

// Foto aufnehmen und auf dem Canvas anzeigen
snapButton.addEventListener('click', () => {
const context = canvas.getContext('2d');
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
context.drawImage(video, 0, 0, canvas.width, canvas.height);
canvas.style.display = 'block';
video.style.display = 'none';
snapButton.disabled = true; // Button deaktivieren, nachdem das Bild aufgenommen wurde
});

// Kamera starten, wenn die Seite geladen wird
window.addEventListener('load', startCamera);
</script>
</body>
</html>