Gdip(default/All) Image Search Fail

Get help with using AutoHotkey and its commands and hotkeys
clow_yakayi
Posts: 39
Joined: 15 Oct 2017, 10:15

Gdip(default/All) Image Search Fail

19 Oct 2017, 15:09

Hey Guy Sorry for bugging you,
I am having issues with Gdip image search, it works most of the time but there is one small bmp it fails to find on the screen
when i made a log to display results the bitmap value is slightly bigger then the haystack of the screen
here is my code and log below it

Code: Select all

FImg(img, transBool:=0, ByRef x:=0, ByRef y:=0, locX:=0, locY:=0, locW:=0, locH:=0)
{
	Log("F FImg " . img . " " . transBool . " " . x . " " . y . " " . locX . " " . locY . " " . locW . " " . locH)
	
	SysGet, VirtualWidth, 78
	SysGet, VirtualHeight, 79
	
	if (not locW)
	{
		locW := VirtualWidth
		Log("-locW " . locW)
	}
	if(not locH)
	{
		locH := VirtualHeight
		Log("-locH " . locH)
	}
	
	if transBool
	{
		trans := "0"
		img .= ".png"
		Log("-trans " . trans)
	}
	else
	{
		img .= ".bmp"
	}
	
	Log("-img " . img)
	
	pToken := Gdip_Startup()
	haystack := Gdip_BitmapFromScreen(0)
	needle := Gdip_CreateBitmapFromFile(img)
	Log("-pToken " . pToken)
	Log("-haystatck " . haystack)
	Log("-needle " . needle)
		
	if transBool
	{
		trans := "0"
		Log("-trans " . trans)
	}
	
	if Gdip_ImageSearch(haystack, needle, XY, locX, locY, locW, locH, 20, trans)
	{
		coords := StrSplit(XY, ",")
		x := coords[1]
		y := coords[2]
		
		Log("-coords " . x . " " . y)
		
		Gdip_DisposeImage(haystack)
		Gdip_DisposeImage(needle)
		Gdip_Shutdown(pToken)
		
		if XY
		{
			Log("F FImg End")
			return 1
		}
		Log("FImg Failed")
		return 0
	}
	Gdip_DisposeImage(haystack)
	Gdip_DisposeImage(needle)
	Gdip_Shutdown(pToken)
	Log("FImg Failed")
	return 0
}

Code: Select all

F FImg divide 0 0 0 0 0 0 0
-locW 1366
-locH 768
-img divide.bmp
-pToken 650795531
-haystatck 55648008
-needle 55649176
FImg Failed
Last edited by clow_yakayi on 20 Oct 2017, 10:31, edited 1 time in total.
clow_yakayi
Posts: 39
Joined: 15 Oct 2017, 10:15

Re: Gdip(default/All) Image Search Fail, needle bitmap value larger then haystack

19 Oct 2017, 15:59

Ok apperantly the needle is always larger number then the haystack but still the issue persists. and its only with this one particular image.
clow_yakayi
Posts: 39
Joined: 15 Oct 2017, 10:15

Re: Gdip(default/All) Image Search Fail

20 Oct 2017, 10:37

Noticed that the more the script runs the less it finds, and sometimes requires sleep breaks to function correctly other times just not working
guest3456
Posts: 2661
Joined: 09 Oct 2013, 10:31

Re: Gdip(default/All) Image Search Fail

20 Oct 2017, 10:42

are you using 64bit version of AHK or 32bit?

can you test and see if it matters?

clow_yakayi
Posts: 39
Joined: 15 Oct 2017, 10:15

Re: Gdip(default/All) Image Search Fail

22 Oct 2017, 10:33

I have switched to ascii 32. it works at the very beginign and sometimes in intervals, but after updating my code it stoped working, instead of having delays inbetweent super functions i just did one statement inside the FImg function.
User avatar
noname
Posts: 509
Joined: 19 Nov 2013, 09:15

Re: Gdip(default/All) Image Search Fail

22 Oct 2017, 12:17

I would remove the pToken := Gdip_Startup() and Gdip_Shutdown(pToken) from the function and only put start at the top of your script , i found if you start/ stop gdip continuously it can fail if it is in rapid succesion.

You could save the haystack to a file or clipboard and take a look if you can see the problematic image that imagesearch does not find clearly.
soundcloud.com/user-32706894
clow_yakayi
Posts: 39
Joined: 15 Oct 2017, 10:15

Re: Gdip(default/All) Image Search Fail

24 Oct 2017, 13:36

thank you, i will try that

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], flyingDman, keokio and 57 guests