K
K
kirillleogky2019-11-17 21:47:38
JavaScript
kirillleogky, 2019-11-17 21:47:38

How to get the pixel color of an image in canvas?

Tell me, I'm uploading an image to canvas and I want to know the color of a certain pixel in the image.
For example, this image:
5dd195fe3417b073073021.png
My code for calculating the color for a canvas without an image (purely using pixel drawing):

ctx.clearRect(0, 0, canvas.width, canvas.height);
      frame4x4.forEach((row, i) => {
        row.forEach((column, j) => {
          ctx.fillStyle = `${currColor.style.backgroundColor}`;
          frame4x4[i][j] = `${currColor.style.backgroundColor}`;
          ctx.fillRect(j * 4, i * 4, 4, 4);
        });
      });

Tell me how to find out the color of a pixel for a specific pixel on canvas? I will use canvas.addEventListener('click', (event) => {}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Shohruh Shaimardonov, 2019-11-17
@joeberetta

already answered

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question