Home >Web Front-end >HTML Tutorial >Get pixel color from HTML canvas

Get pixel color from HTML canvas

WBOY
WBOYforward
2023-09-06 11:41:12680browse

Get pixel color from HTML canvas

To get the pixel color from the canvas, use the following code. This will return 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]

The above is the detailed content of Get pixel color from HTML canvas. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete