Reputation: 23
I am trying to understand how to do some basic operations on image data in javascript. In the following code snippet I have some data, called imgData, and when I send imgData.length to the console I get 1032000 which is correct. The image is 600x430 and 600x430x4=1032000. However, I am trying to sum the R values. When I do this I get 20 which can't possibly be right. Is this something to do with the fact that the image data are uint8 type?
imgData = ctx.getImageData(0, 0, srcImage.width, srcImage.height);
var i;
var sumR;
sumR = 0;
console.log(imgData.data.length);
for (i = 0; i < imgData.data.length; i += 4) {
sumR = sumR = imgData.data[i];
}
console.log(sumR);
Upvotes: 0
Views: 121
Reputation: 4912
As trincot helpfully pointed out, the issue was a typo: +
instead of =
.
Upvotes: 1