我无法从图像中获取 RGB 数据,我正在做的是获取区域的 de x、y、宽度和高度,所以,我想知道区域的 RGB 数据,没有像素, .
我试图使用带有 getImageData 的画布,但它只返回一个像素,我使用库来获取 x、y、w 和 h 的参数,我的图像大小与我的画布相同
这就是我正在做的
const canvas2 = document.getElementById('canvasIMG'); //Get the canvas
const img2 = document.getElementById('imagen');//Get the image
const ctxImagen = canvas2.getContext('2d');//Get the context of canvas
ctxImagen.drawImage(img, 0, 0);
var rgb = ctxImagen.getImageData(ejex,ejey,1000, 1000).data; //"ejex" is the x coordinate and "ejey" is y coordinate, and 1000 is the width and the height, i tried to change the values of w and h, and is the same always, I download a RGB image, and in the console just print the color of both uppset corners
console.log("red ", rgb[0]);
console.log("green ", rgb[1]);
console.log("blue ", rgb[2]);
console.log("alpha ", rgb[3]);
我没有收到任何错误消息。