App With integrated webCam

0

Good morning, If you could give me a hand. my problem is this:

I have an app that integrates the webcam and the photographs taken with it have to be downloaded to the computer and I'm a little lost at this point ... I already have the script that takes the picture ... is the following:

function takepicture() {
   canvas.width = width;
   canvas.height = height;
   canvas.getContext('2d').drawImage(video, 0, 0, width, height);
   var data = canvas.toDataURL('image/png');
   photo.setAttribute('src', data);
 }

 startbutton.addEventListener('click', function(ev){
     takepicture();
   ev.preventDefault();
 }, false);

})();

I just need to be able to download it ... And thanks in advance ..

    
asked by gutierrez.23 14.11.2016 в 14:48
source

1 answer

0

According to this Fiddle the code would be something like this:

function downloadCanvas(link, canvasId, filename) {
    link.href = document.getElementById(canvasId).toDataURL();
    link.download = filename;
}

document.getElementById('download').addEventListener('click', function() {
    downloadCanvas(this, 'canvas', 'test.png');
}, false);

It is explained in English in the same fiddle.

    
answered by 14.11.2016 / 18:51
source