# Pixel Percent

## Recommended Posts

is their a method to find a percent of pixels within an area?

this would be extremly useful for reading health and other attributes on screen like process bar etc.

like "pixelpercent(200,200,400,400, 0xFFFFFF)"

then find use the total amount of pixels and do some basic math to work out how many are white?...

does this exist? or is their a method anyone knows of?

##### Share on other sites

```Func _PixelPercent(\$left, \$top, \$right, \$bottom, \$color)
Local \$count = 0, \$percent = 0
For \$i = \$left to \$right Step 1
For \$j = \$top to \$bottom Step -1
\$poscolor = PixelGetColor(\$i, \$j)
If \$poscolor = \$color Then \$count +=1
Next
Next
\$total = (\$right - \$left + 1) * (\$top - \$bottom + 1)
\$percent = Round(\$count/\$total, 3)
Return \$percent
EndFunc```

Only tested it a couple times. Like PixelSearch, it will be slow if the area is large, since it searches every pixel.

Edited by mikehunt114
IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
##### Share on other sites

ok thank you for your help guys

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...