Answer the question
In order to leave comments, you need to log in
JS: how to accurately count pixels?
Help to accurately calculate the number of pixels. I'm using the fabricjs library and I need to be able to get the total area (of any combination of shapes).
To solve this problem, I count the pixels on the canvas:
function aaa() {
var myConvasPosion = myConvas.getBoundingClientRect();
var count = 0;
for(var i = myConvasPosion.left; i < myConvasPosion.left + myConvasPosion.width; i++){
for(var j = myConvasPosion.top; j < myConvasPosion.top + myConvasPosion.bottom; j++){
var c = canvas.getContext('2d');
var p = c.getImageData(i, j, 1, 1).data;
if(p[0] == 236 && p[1] == 205 && p[2] == 174){
count = count + 1;
}
}
}
console.log(count);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question