GDIP Image Search Failing With Bounded Coordinates? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

GDIP Image Search Failing With Bounded Coordinates?

16 Mar 2018, 16:08

With the image I am searching, the following line returns 32 results (which is correct for the image):

NumResults := Gdip_ImageSearch(pHaystack, pNeedle, ImageCoords, aX-2, aY-2, , , , , , 0)

However, this returns zero results:

NumResults := Gdip_ImageSearch(pHaystack, pNeedle, ImageCoords, aX-2, aY-2, aX + 200, aY + 200, , , , 0)

Despite the fact that per an earlier search I did, the first result is at aX, aY. I've tested this with a variety of circumstances and come to the inescapable conclusion that ANY time OuterX2 or OuterY2 is non-zero, Gdip_ImageSearch returns zero results, regardless of the haystack or needle.

Has anyone else experienced this bug? Do you have any idea how to fix it?

Here is my full code, in case it helps, with the non-working image search commented out.

Code: Select all

if !pToken := Gdip_Startup()	; Start GDI+ for advanced image handling
{
	MsgBox, 48, % "GDI+ error!", % "GDI+ failed to start. Please ensure you have gdiplus on your system!"
	return
}
	
AnchorPath := A_WorkingDir . "\Utils\Anchor.png"
pNeedle := Gdip_CreateBitmapFromFile(AnchorPath)
pHwnd := WinExist("A")
pHaystack := Gdip_BitmapFromHWND(pHwnd)	; Create the haystack from the active window
	
Gdip_ImageSearch(pHaystack, pNeedle, ImageCoords)
Pos := InStr(ImageCoords, ",")			; Split the coordinates into X and Y
aX := SubStr(ImageCoords, 1, Pos-1)
aY := SubStr(ImageCoords, Pos+1)
	
;NumResults := Gdip_ImageSearch(pHaystack, pNeedle, ImageCoords, aX-2, aY-2, aX + 200, aY + 200, , , , 0)
NumResults := Gdip_ImageSearch(pHaystack, pNeedle, ImageCoords, aX-2, aY-10, , , , , , 0)
	
Gdip_DisposeImage(pNeedle)
Gdip_DisposeImage(pHaystack)
Gdip_Shutdown(pToken)
	
return NumResults
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: GDIP Image Search Failing With Bounded Coordinates?

16 Mar 2018, 19:20

I remember something about the function being a bit unintuitive, and that it had some differences with ImageSearch. Perhaps something like this happened: the function failed if you specified boundary values beyond the size of the image.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: GDIP Image Search Failing With Bounded Coordinates?

19 Mar 2018, 08:17

Thank you, Helgef. Glad to know I'm not going insane, and that it is a GDIP bug. The fix posted in that thread (adding "UInt" as a parameter to the four NumGet functions) worked for me.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: jollyjoe and 319 guests