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

Get pixel color from HTML canvas

WBOY
Release: 2023-09-06 11:41:12
forward
675 people have browsed it

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]
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template