Skip to content

Instantly share code, notes, and snippets.

@newshorts
Forked from anantn/getusermedia_picture.html
Created April 28, 2014 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save newshorts/11383774 to your computer and use it in GitHub Desktop.
Save newshorts/11383774 to your computer and use it in GitHub Desktop.
<html>
<body>
<video id="v" width="300" height="300"></video>
<input id="b" type="button" disabled="true" value="Take Picture"></input>
<canvas id="c" style="display:none;" width="300" height="300"></canvas>
</body>
<script>
navigator.getUserMedia({video: true}, function(stream) {
var video = document.getElementById("v");
var canvas = document.getElementById("c");
var button = document.getElementById("b");
video.src = stream;
button.disabled = false;
button.onclick = function() {
canvas.getContext("2d").drawImage(video, 0, 0, 300, 300, 0, 0, 300, 300);
var img = canvas.toDataURL("image/png");
alert("done");
};
}, function(err) { alert("there was an error " + err)});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment