Skip to content

Instantly share code, notes, and snippets.

@z-------------
Created April 27, 2014 12:44
Show Gist options
  • Save z-------------/11344689 to your computer and use it in GitHub Desktop.
Save z-------------/11344689 to your computer and use it in GitHub Desktop.
function getPixelColor(x,y,canvas){ // where canvas is an HTMLCanvasElement
var ctx = canvas.getContext("2d");
var idata = ctx.getImageData(0,0,canvas.width,canvas.height);
var p = ((y*(idata.width*4)) + (x*4));
var d = idata.data;
return [d[p],d[p+1],d[p+2]]; // returns an array of that pixel's red, green and blue values
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment