Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created April 29, 2019 15:36
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 parzibyte/c79d42201abbc2f936c347c15ad242d8 to your computer and use it in GitHub Desktop.
Save parzibyte/c79d42201abbc2f936c347c15ad242d8 to your computer and use it in GitHub Desktop.
//Escuchar el click del botón para tomar la foto
$boton.addEventListener("click", function() {
//Pausar reproducción
$video.pause();
//Obtener contexto del canvas y dibujar sobre él
let contexto = $canvas.getContext("2d");
$canvas.width = $video.videoWidth;
$canvas.height = $video.videoHeight;
contexto.drawImage($video, 0, 0, $canvas.width, $canvas.height);
let foto = $canvas.toDataURL(); //Esta es la foto, en base 64
let enlace = document.createElement('a'); // Crear un <a>
enlace.download = "foto_parzibyte.me.png";
enlace.href = foto;
enlace.click();
//Reanudar reproducción
$video.play();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment