I am just trying to get in the habit of pixel manipulation and it doesn't change anything.
I use the following loop to invert each pixel:
var newImage = context.createImageData(canvas.width, canvas.height);
var arr = context.getImageData(0, 0, canvas.width, canvas.height);
var pixels = arr.data;
for(var i = 0; i < pixels.length; i+=4){
var r = 255 - pixels[i];
var g = 255 - pixels[i + 1];
var b = 255 - pixels[i + 2];
var a = pixels[i + 3];
newImage.data[i] = r;
newImage.data[i + 1] = g;
newImage.data[i + 2] = b;
newImage.data[i + 3] = a;
}
yet when I try and clear the canvas and rewrite it, nothing happens:
context.clearRect(0, 0, canvas.width, canvas.height);
context.putImageData(newImage, 0, 0);
why is this not working? what am I doing wrong?
onLoad
callback of the image ;) – Paul Rad