Syntax error Get pixel color from canvas with HTML

Get pixel color from canvas with HTML



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]
Updated on: 2020-03-04T06:30:51+05:30

348 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements