I need to get the ratio of transparent/opaque pixels in my canvas. What is the best way to do this?
UPDATE: Based on the below posts I ended up writing this code:
function getNumberOfAlphaPixels(can) {
var step = 200; //We skip 200 pixels to make it work faster
var ctx = can.getContext('2d');
var imgd = ctx.getImageData(0, 0, can.width, can.height);
var pix = imgd.data;
var alphaPixelsNum = 0;
for (var i = 0; i < pix.length; i += 4*step) {
if (pix[i+3] == 0) {
alphaPixelsNum += step;
}
}
return alphaPixelsNum;
}