Get pixel color from canvas with HTML

HTMLWeb DevelopmentFront End Technology

To get the pixel color from canvas, use the following code. This returns the color in rgba −

var index = (Math.floor(y) * canvasWidth + Math.floor(x)) * 4

// color in rgba
var r = data[index]
var g = data[index + 1]
var b = data[index + 2]
var a = data[index + 3]
raja
Updated on 04-Mar-2020 06:30:51

Advertisements