Page 1 of 1

Can't find Image with GDI+

Posted: 01 Feb 2024, 00:23
by AnhurChivas
I found this code on the internet and tried to use it, but it cannot find the image on the screen. Even though I set the variation to 50-60, it cannot find it. What is the problem? can you help me?

Code: Select all

#Include Gdip_All.ahk
#Include Gdip_ImageSearch.ahk

bStat := GDI_ImageSearch("Target Client", OutX, OutY, 0, 0, 1366, 768, 0, 1, "Enemy.png", OutError)
if(bStat)
{
	 msgbox, % "Found! -> X: " OutX " Y: " OutY
}
else
{
	 msgbox, Not Found!
}

GDI_ImageSearch(WindowTitle="", byref OutputVarX=0, byref OutputVarY=0, X1=0, Y1=0, X2=0, Y2=0, Variation=30, Direct=1, ImageFile="", byref Error="")
{
	 WinGet, hwnd, ID, %WindowTitle%
	 pToken := Gdip_Startup()
	 pBitmapHayStack := Gdip_BitmapFromhwnd(hwnd)
	 if(pBitmapHayStack = 0)
	 {
		  Error := "Failed to retrieve target window information!"
		  return false
  }

	 pBitmapNeedle := Gdip_CreateBitmapFromFile(ImageFile)
	 if(pBitmapNeedle = 0)
	 {
		  Error := "Could not load image file!"
		  return false
	 }

	 sleep, 10

	 if(Gdip_ImageSearch(pBitmapHayStack, pBitmapNeedle, list, X1, Y1, X2, Y2, Variation, 0x000000, Direct, 1) )
	 {
		  StringSplit, LISTArray, LIST, `,

  		OutputVarX := LISTArray1
		  OutputVarY := LISTArray2

		  Gdip_DisposeImage(pBitmapHayStack)
		  Gdip_DisposeImage(pBitmapNeedle)
		  Gdip_Shutdown(pToken)

		  return true
	 }
	 else
	 {
		  Gdip_DisposeImage(pBitmapHayStack)
		  Gdip_DisposeImage(pBitmapNeedle)
		  Gdip_Shutdown(pToken)

		  Error := "No image found!"
		  return false
	 }
}

Re: Can't find Image with GDI+

Posted: 01 Feb 2024, 04:14
by boiler
There are a number of reasons why it may not have worked.

Based on the name of your image file, I’m guessing that you’re trying to find an image of an enemy in a game. Is that right? Does the image contain any background that wouldn’t be the same when the enemy appears again?

I’m guessing the title of your window isn’t really Target Client is it? Are you running it with those words there?

Re: Can't find Image with GDI+

Posted: 01 Feb 2024, 11:28
by AnhurChivas
boiler wrote:
01 Feb 2024, 04:14
There are a number of reasons why it may not have worked.

Based on the name of your image file, I’m guessing that you’re trying to find an image of an enemy in a game. Is that right? Does the image contain any background that wouldn’t be the same when the enemy appears again?

I’m guessing the title of your window isn’t really Target Client is it? Are you running it with those words there?
Hello, yes, I'm trying to find an enemy and "Target Client" is not the actual window, I wrote it as an example. There is no problem with the image file or its location because when I search with ImageSearch, it finds the enemy.
The picture I'm looking for is the enemy's health bar and it doesn't change (as a variation), even if I set the variation to 50-60, it doesn't find it anyway. It finds it without any problems with ImageSearch.


[Mod action: Topic moved to the "Gaming" section.]

Re: Can't find Image with GDI+

Posted: 01 Feb 2024, 18:05
by AnhurChivas
Well, my toic moved to the Gaming section but it is not about only "gaming".
GDI+ ImageSearch does not work in game or anywhere else.

Re: Can't find Image with GDI+

Posted: 01 Feb 2024, 18:49
by boiler
Gdip_ImageSearch works in general. I and many others have successfully used it quite a lot. Since your specifics were about a game, I moved the topic because there are often issues specific to game applications that are the problem. I can move it back if you'd like since you say you're not able to get it to work in general. I suggest you post a screenshot of the window in which you're searching and your reference image that you are trying to find so that others can try to identify the problem or perhaps not be able to replicate it. And post the exact script that you ran that is not able to find the reference image in that screenshot (after trying and failing to find it in that screenshot, of course).