vtk.js

vtk.js


canvas 图片合并(2)

<pre><code class="language-javascript">/** * 合并六张图为一张 * @param {*} imgList * @param {*} width * @param {*} height * @returns */ export async function mergeCanvas6(imgList, width, height) { return new Promise((resolve, reject) =&amp;gt; { // 创建 canvas 节点并初始化 const canvas = document.createElement('canvas'); canvas.width = width * 2 + 8; // 间隔8像素 canvas.height = height * 4 + 24; // 间隔8像素 const context = canvas.getContext('2d'); let count = 0; imgList.forEach((item, index) =&amp;gt; { const img = new Image(); img.src = item; // 跨域 img.crossOrigin = 'Anonymous'; img.onload = () =&amp;gt; { index === 0 &amp;amp;&amp;amp; context.drawImage(img, 0, 0, width, height); index === 1 &amp;amp;&amp;amp; context.drawImage(img, width + 8, 0, width, height); index === 2 &amp;amp;&amp;amp; context.drawImage(img, 0, height + 8, width, height); index === 3 &amp;amp;&amp;amp; context.drawImage(img, width + 8, height + 8, width, height); index === 4 &amp;amp;&amp;amp; context.drawImage(img, 0, 2 * height + 16, width * 2 + 8, height); index === 5 &amp;amp;&amp;amp; context.drawImage(img, 0, height * 3 + 24, width * 2 + 8, height); count++; if (count === imgList.length) { resolve(canvas.toDataURL('image/jpeg')); } }; }); }); }</code></pre>

页面列表

ITEM_HTML