Uncaught DOMException: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The source width is 0.
But I'm doing the same thing to receive the canvas width, which is 664px;
<canvas id="viewport" width="664px" height="664px"></canvas>
<script>
let canvas = document.getElementById('viewport'),
context = canvas.getContext('2d');
make_base();
console.log("aqui "+imageData.data)
numPixels = imageData.width * imageData.height;
let count = 0;
for ( let i = 0; i < numPixels; i++ ) {
let r = pixels[ i * 4 ],
g = pixels[ i * 4 + 1 ],
b = pixels[ i * 4 + 2 ];
if(r == 255 && g == 0 && b == 0){
count++;
}
}
alert("O numero de pixels vermelhor é :"+count);
}
</script>