-
Notifications
You must be signed in to change notification settings - Fork 0
/
open-camera.html
54 lines (54 loc) · 2.02 KB
/
open-camera.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<html>
<head>
<meta charset="utf-8">
<title>Tirar Fotos</title>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<style>
video { border: 1px solid #ccc; display: block; margin: 0 0 20px 0; }
#canvas { margin-top: 20px; border: 1px solid #ccc; display: block; }
</style>
</head>
<body>
<div>
<div><video id="video" width="640" height="480" autoplay></video></div>
<div><button id="snap">Tirar Foto</button></div>
<div><button id="save">Salvar Foto</button></div>
<div><canvas id="canvas" width="640" height="480"></canvas></div>
<script>
window.addEventListener("DOMContentLoaded", function() {
var canvas = document.getElementById("canvas"),
context = canvas.getContext("2d"),
video = document.getElementById("video"),
videoObj = { "video": true },
errBack = function(error) {
console.log("Video capture error: ", error.code);
};
if(navigator.getUserMedia) {
navigator.getUserMedia(videoObj, function(stream) {
video.src = stream;
video.play();
}, errBack);
} else if(navigator.webkitGetUserMedia) {
navigator.webkitGetUserMedia(videoObj, function(stream){
video.src = window.webkitURL.createObjectURL(stream);
video.play();
}, errBack);
}
else if(navigator.mozGetUserMedia) {
navigator.mozGetUserMedia(videoObj, function(stream){
video.src = window.URL.createObjectURL(stream);
video.play();
}, errBack);
}
}, false);
document.getElementById("snap").addEventListener("click", function() {
canvas.getContext("2d").drawImage(video, 0, 0, 640, 480);
//alert(canvas.toDataURL());
});
document.getElementById("save").addEventListener("click", function() {
$.post('fotossalvar.php', {imagem:canvas.toDataURL()}, function(data){
},'json');
});
</script>
</body>
</html>