pixels[i] = 0 ;
would not change the display because you are affecting only the original array of pixels. Plus you are not writing back to the canvas when the loop is done. To affect the new array (after drawing on it), use
newPixels[i] = 0;
. I tried it, and as expected, it set the red channel to zero making the image a turquoise color (mix of green and blue).var imageData2 = context.getImageData(0, 0, 525, 482);
var newPixels = imageData2.data;
for (var i = 0, il = pixels.length; i < il; i += 4) {
if(pixels[i] == 206 && pixels[i+1] == 206 && pixels[i+2] == 206){
newPixels[i] = 206;
newPixels[i+1] = 206;
newPixels[i+2] = 206;
}
}
context.putImageData(imageData2, 0, 0);
if(pixels[i] != 255 || pixels[i+1] != 204 || pixels[i+2] != 153){
newPixels[i] = pixels[i];
newPixels[i+1] = pixels[i+1];
newPixels[i+2] = pixels[i+2];
}
Open in new window