I'm attempting to desaturate an image. I'm currently loading it, parsing the image data, but I can't get it to write back to the canvas.
I've followed all of the directions to do
context.putImageData(imagedata,0,0);
I do this, but the image data doesn't change. "ctx" is the context of the image that is previously loaded that is being turned greyscale.
greyscale: function grayscale(ctx){
var id = ctx.getImageData(0,0, ctx.canvas.width, ctx.canvas.height);
for(var i=0; i<id.height; i++){
for(var e=0; i<id.width; i++){
var index = (e*4)*id.width+(i*4);
var avg = (id.data[index] + id.data[index+1] + id.data[index+2]) / 3
id.data[index] = avg;
id.data[index+1] = avg;
id.data[index+2] = avg;
}
}
ctx.putImageData(id,0,0);
}