About using PixelSearch for a single pixel Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
Tykvesh
Posts: 7
Joined: 12 Jul 2023, 04:03

About using PixelSearch for a single pixel

Post by Tykvesh » 11 May 2024, 16:18

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)
}
Rohwedder
Posts: 7719
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: About using PixelSearch for a single pixel  Topic is solved

Post by Rohwedder » 12 May 2024, 02:22

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)
}
User avatar
Tykvesh
Posts: 7
Joined: 12 Jul 2023, 04:03

Re: About using PixelSearch for a single pixel

Post by Tykvesh » 12 May 2024, 23:32

@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.
Post Reply

Return to “Ask for Help (v2)”