base64 转 imageData
<pre><code class="language-javascript">/**
*
* @param {*} base64
*/
export async function base64ToImageDataRGB(base64, width, height) {
return new Promise((resolve, reject) =&gt; {
const img = document.createElement('img');
img.onload = function () {
const offscreenC = new OffscreenCanvas(width, height);
const context = offscreenC.getContext('2d');
context.drawImage(img, 0, 0);
let imgData = context.getImageData(0, 0, width, height);
let arrData = imgData.data.filter((item, index) =&gt; {
if ((index + 1) % 4 === 0) {
return false;
}
return true;
});
imgData = null;
arrData = new Uint8Array(arrData);
resolve(arrData);
};
img.src = base64;
});
}</code></pre>