Question about searching images using Gdip_ImageSearch Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
styner
Posts: 7
Joined: 24 Mar 2018, 05:09

Question about searching images using Gdip_ImageSearch

19 Aug 2018, 21:21

Hi,

I'm trying to search images on a client hiding behind another windows using simple function that I found but I seem to have some issues with it. I'm also using Gdip_Imagesearch with it.

Code: Select all

search_img(image,hwnd, byref vx, byref vy) {
	pToken:=Gdip_Startup()
	SetWorkingDir %A_ScriptDir%
	 
	pBitmapHayStack:=Gdip_BitmapFromhwnd(hwnd) 
	pBitmapNeedle:=Gdip_CreateBitmapFromFile(image) 

	if Gdip_ImageSearch(pBitmapHayStack,pBitmapNeedle,list,0,0,0,0,50,,1,1)
	{  
		StringSplit, LISTArray, LIST, `,  
		vx:=LISTArray1 
		vy:=LISTArray2
		Gdip_DisposeImage(pBitmapHayStack), Gdip_DisposeImage(pBitmapNeedle)
		Gdip_Shutdown(pToken)
		return true
	}
	else 
	{
		Gdip_DisposeImage(pBitmapHayStack), Gdip_DisposeImage(pBitmapNeedle)
		Gdip_Shutdown(pToken)
		return false
	}
}
What I'm trying to do was, using that search_img function, I was trying to covert my Imagesearch lines in my main script.

Code: Select all

ImageSearch, x, y, %pos_x%, %pos_y%, %x_right%, %y_bottom%, *50 %A_ScriptDir%\Image\victory%A_index%.bmp
into

Code: Select all

WinGet,Nox,ID, NoxPlayer
	loop, 4{
	if(Search_img(%A_ScriptDir%\Image\victory%A_index%.bmp, Nox,x,y)){
			tooltip hi %x% %y% %A_index%
			sleep, 1000
		}	
		else{
			tooltip bye
			sleep, 1000
		}
	}
I got these 3 problems after converting but I don't know how to tackle it.

1. All of my images r under a folder called "Image". When I tried to add location at search_img function, it says it's illegal expression. It only seems to accept file names with "" in it.

2. Some of my ImageSearch line have %A_index% so it can go through loop to compare different number of images. How do I also incorporate that into Search_img function?

3. Even if I have a wrong image to compare, it still says "hi" according to the script. How I make it return "bye" if the given image is not on the client that I asked to search?
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Question about searching images using Gdip_ImageSearch

20 Aug 2018, 01:28

IN AHK there are 2 seperate syntaxes that both exist.
One is the command syntax the other is the expression syntax.

Command syntax is everything that starts with a command name at the start of the line and then has its parameters seperated by a ,
e.g. :

Code: Select all

ImageSearch, x, y, %pos_x%, %pos_y%, %x_right%, %y_bottom%, *50 %A_ScriptDir%\Image\victory%A_index%.bmp
In the command syntax you can write text directly as is but need to use %% around variables.

The expression syntax is the rest - e.g. functions:

Code: Select all

Search_img()
This is a function
The difference to the command syntax mode is that variables dont use %% around variables but you use "" around text.

The name of a file is text.
Recommends AHK Studio
styner
Posts: 7
Joined: 24 Mar 2018, 05:09

Re: Question about searching images using Gdip_ImageSearch

20 Aug 2018, 04:04

oh so I was playing with "" and found out that I just need to use "Image/victory.bmp" format in search_img function to solve problem 1 and 3. Is there any ways to integrate A_index somewhere in there? I tried to use "Image/victory%A_index%.bmp" but that didn't work out.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Question about searching images using Gdip_ImageSearch  Topic is solved

20 Aug 2018, 05:37

Code: Select all

if(Search_img(A_ScriptDir "\Image\victory" A_index ".bmp", Nox,x,y)){
e: misplaced quotes
Last edited by swagfag on 20 Aug 2018, 10:48, edited 2 times in total.
styner
Posts: 7
Joined: 24 Mar 2018, 05:09

Re: Question about searching images using Gdip_ImageSearch

20 Aug 2018, 10:47

swagfag wrote:

Code: Select all

if(Search_img("A_ScriptDir\Image\victory" A_index ".bmp", Nox,x,y)){
oh shoot! this works! Although I had to get rid of A_scriptdir part but after that, it worked! Many thanks guys!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], hiahkforum, NullRefEx, XMCQCX and 120 guests