I have a .png image with 500 pixels of width and 400 pixel of height. I also have a canvas that has the same dimensions (500x400).
I want to get de RGB value of a pixel gives it x and y coordinates. For example:
Give the pixel at coordinate x = 0 and y = 0 (top-left corner) in canvas/image, then print:
R: 255, G: 200, B:30
HTML:
<canvas id="myCanvas" width="500" height=400" style="bprder:1px, solid, #000000">
Your browser does not support the HTML5 canvas tag</canvas>
<p id="pixelValues"></p>
I want to print the RGB value in HTML file, so the JS to print this should be something like this:
document.getElementById("pixelValues").innerHTML =//the variable that has the RGB values of the pixel at coordinates x-y.
I tried to use getImageData method but doesn't work :/
I hope this image makes the issue clearer:
EDIT: My problem had nothing to do with my code. Afterwards I noticed that the console was giving CORS error, so I solved the problem by changing the src of the image to a link where CORS was enabled.
