If you want to extract a specific pixel color by passing the coordinates of the pixel to a function, this is useful
var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); function detectColor(x,y){ data=ctx.getImageData(x,y,1,1).data; col={ r:data[0], g:data[1], b:data[2] }; return col; }
x, y is the coordinate you want to filter.
var color=detectColor(x,y)
Color is an object, you will get the rgb value by color.r, color.g, color.b.
MD Rijwan Oct 13 '18 at 18:38 2018-10-13 18:38
source share