Search completed in 1.09 seconds.
1 results for "takePicture":
Taking still photos with WebRTC - Web APIs
WebAPIWebRTC APITaking still photos
handle clicks on the button to capture a still photo each time the user clicks the startbutton, we need to add an event listener to the button, to be called when the click event is issued: startbutton.addeventlistener('click', function(ev){ takepicture(); ev.preventdefault(); }, false); this method is simple enough: it just calls our takepicture() function, defined below in the section capturing a frame from the stream, then calls event.preventdefault() on the received event to prevent the click from being handled more than once.
... capturing a frame from the stream there's one last function to define, and it's the point to the entire exercise: the takepicture() function, whose job it is to capture the currently displayed video frame, convert it into a png file, and display it in the captured frame box.
... the code looks like this: function takepicture() { var context = canvas.getcontext('2d'); if (width && height) { canvas.width = width; canvas.height = height; context.drawimage(video, 0, 0, width, height); var data = canvas.todataurl('image/png'); photo.setattribute('src', data); } else { clearphoto(); } } as is the case any time we need to work with the contents of a canvas, we start by getting the 2d drawing context for the hidden canvas.