Jump to content

Pixel Percent


Nebieboy
 Share

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?

thanks in advance

Link to comment
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]
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...