js 转换image data 成黑白色。
We can even make it pure black and white by using the following calculations:
- black = 0 - 382
- white = 383 - 765
And it will result in the following loop:
for (i = 0; i < imgData.data.length; i += 4) {
let count = imgData.data[i] + imgData.data[i + 1] + imgData.data[i + 2];
let colour = 0;
if (count > 383) colour = 255;
imgData.data[i] = colour;
imgData.data[i + 1] = colour;
imgData.data[i + 2] = colour;
imgData.data[i + 3] = 255;
}