gpt4 book ai didi

javascript - 如何快速从源数组中读取子数组

转载 作者:行者123 更新时间:2023-12-03 04:04:34 25 4
gpt4 key购买 nike

我目前使用以下内容:

const canvasOneBuffer = new Uint8Array(canvasOneImageData.data.buffer);
// within an x/y loop:
const newPixel1Data0 = canvasOneBuffer[4 * (x + y * canvasOne.width) + 0];
const newPixel1Data1 = canvasOneBuffer[4 * (x + y * canvasOne.width) + 1];
const newPixel1Data2 = canvasOneBuffer[4 * (x + y * canvasOne.width) + 2];
const newPixel1Data3 = canvasOneBuffer[4 * (x + y * canvasOne.width) + 3];
const pixel1Data = new Uint8ClampedArray(4);
pixel1Data[0] = newPixel1Data0;
pixel1Data[1] = newPixel1Data1;
pixel1Data[2] = newPixel1Data2;
pixel1Data[3] = newPixel1Data3;

但这似乎有点迟钝。有什么方法可以通过从缓冲区数组中读取一次来创建新的 Uint8ClampedArray(4); 吗?

最佳答案

你的意思是像

const pixel1Data = canvasOneBuffer.slice(0, 4)
.map(canvasItem => {
// do what ever with canvasItem
});

关于javascript - 如何快速从源数组中读取子数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44617792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com