Im trying to get the amount of pixels that is transparent in a png through Processing by using the get() command or img.get(). I've tried putting a white background and use this code but the output isn't near what it should be for the picture I test with which I know is filled with about 50% black and rest transparent.
I used this code and expected to get value of "v" too land in the 125xxxx region since I know approx 50% of the picture femtiofemtio.png is black:
PImage img;
color currentColor;
void setup() {
size(1176,2172);
currentColor = color(0);
img = loadImage("femtiofemtio.png");
}
void draw() {
int v = 0;
background(255);
image(img, 0, 0);
for (int x = 1; x < 1176; x = x+1) {
for (int y = 1; y < 2172; y = y+1) {
currentColor = img.get(x,Y);
if (alpha(currentColor)==255){
v=v+1;
println(v);
}
}
}
//print(v/2554272);
print("end ");
exit();
}