function hecheng (){ // 创建一个canvas const d2 = testCanvas.getContext('2d'); // 准备图片1 const url = URL.createObjectURL(file.files[0]); var img = document.createElement("img"); img.src = url; // 准备图片2 const url1 = URL.createObjectURL(file1.files[0]); var img1 = document.createElement("img"); img1.src = url1; setTimeout(()=>{ d2.drawImage(img, 10, 10); d2.drawImage(img1, 10, 10); const base64 = testCanvas.toDataURL(); let data = atob(base64.substring("data:image/png;base64,".length)), asArray = new Uint8Array(data.length); for( let i = 0, len = data.length; i < len; ++i ) { asArray[i] = data.charCodeAt(i); } var file0 = new File( [asArray.buffer], 'foo.png', { type: 'image/png', } ); const url = URL.createObjectURL(file0); var img2 = document.createElement("img"); img2.src = url; document.body.appendChild(img2); }, 1000) }
标签:文件,const,img,上传,file,var,document,data From: https://www.cnblogs.com/liao1992/p/17729386.html