PNG count not transparent pixels
Posted: Sun Jan 01, 2017 1:32 am
Hi,
I needed to compare the area of 2 estates.
Ok, I used google maps and grabbed the pictures.
I loaded the pictures in gimp and cut out the estates.
Then I saved each estate as png with transparence.
Now I needed only a tool to count the pixels.
After a short time of searching I used my 'swiss army knife' called PB
As test for the truth I store a bmp with all counted pixels in red.
In my case it worked.
Maybe someone can use it too.
Happy new year,
Bernd
I needed to compare the area of 2 estates.
Ok, I used google maps and grabbed the pictures.
I loaded the pictures in gimp and cut out the estates.
Then I saved each estate as png with transparence.
Now I needed only a tool to count the pixels.
After a short time of searching I used my 'swiss army knife' called PB

Code: Select all
UsePNGImageDecoder()
Filename$ = OpenFileRequester("Choose a file", "", "PNG|*.png", 0)
If Filename$ <> ""
If LoadImage(0, Filename$)
w = ImageWidth(0)
h = ImageHeight(0)
If StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_AllChannels)
For y = 0 To h - 1
For x = 0 To w - 1
P = Point(x, y)
If Alpha(P) <> 0
;Debug Str(x) + "x" + Str(y) + " " + Str(Alpha(P))
Count + 1
Plot(x, y, $FF0000FF)
EndIf
Next x
Next y
StopDrawing()
SaveImage(0, Filename$ + ".bmp", #PB_ImagePlugin_BMP)
MessageRequester("Info", "Found " + Str(Count) + " pixel")
EndIf
EndIf
EndIf
In my case it worked.
Maybe someone can use it too.
Happy new year,
Bernd