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;
}
标签:成黑,colour,js,black,imgData,data,image,255
From: https://www.cnblogs.com/Regina-wisdom/p/17434942.html