Вы можете сохранить изображение src как base64, используя canvas.toDataURL("img/png")
:
captureButton.addEventListener('click', () => {
// Draw the video frame to the canvas.
context.drawImage(player, 0, 0, canvas.width, canvas.height);
// Get the image src (base64)
const imgSrc=canvas.toDataURL("img/png");
// Apply the src to an image element
const img = new Image();
img.src = imgSrc
// Add the newly created image to the DOM
// A html element with the class .image-holder needs to exist on the page
document.querySelector('.image-holder').appendChild(img);
// Store the src in local storage
localStorage.setItem('imgSrc', imgSrc)
});
Чтобы сохранить его на локальном компьютере, вы можете использовать что-то вроде FileSaver (спасибо этот SO ответ):
captureButton.addEventListener('click', () => {
// Draw the video frame to the canvas.
context.drawImage(player, 0, 0, canvas.width, canvas.height);
// save the file
canvas.toBlob(function(blob) {
saveAs(blob, "image-name.jpg");
});
});
edit: рабочий пример здесь https://codepen.io/relativemc/pen/QWLoOZO