通过视频,使用画布截图
代码:
//视频可播放,就可以截图
var captureImage = function() {
console.log(localStorage.getItem("name"))
var canvas = document.createElement("canvas");
canvas.width = video.videoWidth * scale;
canvas.height = video.videoHeight * scale;
canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
// 解决 canvas 将图片转为base64报错: Uncaught DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement' 跨域
console.log(video.currentTime.toFixed(0))
var img = document.createElement("img");
img.setAttribute("crossOrigin",'Anonymous')
img.src = canvas.toDataURL("image/png");
var obj={src:canvas.toDataURL("image/png"),timer:video.currentTime.toFixed(0)}
arr.push(obj)
output.appendChild(img);
};