Page 1 of 1
About using PixelSearch for a single pixel
Posted: 11 May 2024, 16:18
by Tykvesh
I've been using this function as PixelGetColor alternative for cases when the color may have a variance. It works great, but I was wondering if what I'm doing is the best method for this.
Code: Select all
PixelMatchColor(x, y, color, variance)
{
Return PixelSearch(&a, &b, x, y, x, y, color, variance)
}
Re: About using PixelSearch for a single pixel Topic is solved
Posted: 12 May 2024, 02:22
by Rohwedder
Hallo,
I compared it with a PixelMatchColor2() based on ImageSearch. Result: No relevant difference in speed!
Try:
Code: Select all
#Requires AutoHotkey v2.0
CoordMode "Pixel", "Screen"
q::
{
x:=100, y:=100 , Color := 0x2D7D9B, Variance := 10
T := A_TickCount
Loop 100
PixelMatchColor(x, y, Color, Variance)
T1 := A_TickCount
Loop 100
PixelMatchColor2(x, y, Color, Variance)
T2 := A_TickCount
MsgBox T1-T " > " T2-T1
}
PixelMatchColor(x, y, Color, Variance)
{
Return PixelSearch(&a, &b, x, y, x, y, Color, Variance)
}
PixelMatchColor2(x, y, Color, Variance)
{
Static OldColor:="", Handle
(OldColor = Color) ?"": (Handle := DllCall("CreateBitmap", "Int", 1, "Int", 1
, "Int", 0x1, "Int", 32, "UIntP", Color, "Ptr"), OldColor := Color)
Return ImageSearch(&a, &b, x, y, x, y, "*" Variance " HBITMAP:*" Handle)
}
Re: About using PixelSearch for a single pixel
Posted: 12 May 2024, 23:32
by Tykvesh
@Rohwedder thanks for testing! On average they perform the same, and the worst result was 844 > 765 (PixelSearch vs ImageSearch). I am satisfied with this conclusion.