Created
March 1, 2017 17:54
-
-
Save glaucia86/7891f9335d593db3b18fa6591032259f to your computer and use it in GitHub Desktop.
Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tirarFoto(){ | |
var esconder_canvas = document.querySelector('canvas'), | |
video = document.querySelector('video.camera_stream'), | |
imagem = document.querySelector('img.foto'), | |
// Retornará o tamanho exato do elemento do video: | |
largura = video.videoWidth, | |
altura = video.videoHeight, | |
//Objeto de contexto para trabalhar com a tela | |
context = esconder_canvas.getContext('2d'); | |
// Define a tela com as mesmas dimensões que o vídeo. | |
esconder_canvas.width = width; | |
esconder_canvas.height = height; | |
// Desenhará uma cópia do quadro atual do vídeo na tela. | |
context.drawImage(video, 0, 0, width, height); | |
// Retornará a image através do dataURL para o canvas: | |
var imageDataURL = esconder_canvas.toDataURL('image/png'); | |
// Define o dataURL como fonte de um elemento de imagem, mostrando a foto capturada: | |
image.setAttribute('src', imageDataUrl); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment