Jump to content

# _PixelPercent

## Recommended Posts

```;===============================================================================
;
; Function Name:    _PixelPercent()
; Description:      Determine the percentage of pixels in a given area
;                   that are a given color
; Parameter(s):     \$left - left coordinate of rectangle
;                   \$top - top coordinate of rectangle
;                   \$right - right coordinate of rectangle
;                   \$bottom - bottom coordinate of rectangle
;                   \$color - the color code to search for (Decimal)
; Requirement(s):   None
; Return Value(s):  On Success - Returns the decimal percentage of pixels found over pixels searched
;                   On Failure - Returns a blank string and sets @error (to 1 for incorrect parameters)
; Author(s):        Radagast
;                   Thanks be to the author of PixelGetColor
;
;===============================================================================

Func _PixelPercent(\$left, \$top, \$right, \$bottom, \$color)
If Not IsNumber(\$left) Or Not IsNumber(\$top) Or Not IsNumber(\$right) Or Not IsNumber(\$bottom) Then
@error = 1
Return ""
EndIf
Local \$poscolor, \$total, \$percent, \$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```

Probably very similar to PixelSearch? Returns a percentage instead of stopping at the first found pixel.

Btw, can someone tell me where I can check out the source for functions such as PixelSearch? Not the Include functions, the base functions...I've looked around a bit but haven't been able to find them.

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]

## 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
• ### Recently Browsing   0 members

• No registered users viewing this page.
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...