数组的内容: data.length: w * h * 4 r: 0 - 255 g: 0 - 255 b: 0 - 255 a: 0 - 255 Math.round(255 * a) 数组遍历:
const data = context.getImageData(0, 0, canvas.width, canvas.height).data, len = canvas.width * canvas.height;
for(let k = 0, x, y, r, g, b, a, i; k < len; k++){ x = k % width; y = Math.floor(k / width);
i = k*4; r = data[i] g = data[i+1] b = data[i+2] a = data[i+3] console.log(x, y, r, g, b, a, i); }
标签:canvas,ImageData,javascript,height,width,data,Math,255 From: https://www.cnblogs.com/weihexinCode/p/16652500.html