Hi
Masonjar13, thanks for you interest in
Gdip_ImageSearch() and sorry for the delay.
(I've unfortunately been from the forums for a few weeks now)
Please note that you should
always dispose everything (and subsequently shutdown GDIP), even if the search fails.
I fixed the code to do so, but may wanna restart your PC if you've already executed the unsafe version.
With that said, I couldn't reproduce your problem. Here's the exact test script I ran for ~3000 iterations:
(tested with AutoHotkey111500.exe)
Code: Select all
#NoEnv
ListLines, Off
SetBatchLines, -1
Process, Priority,, High
#Include GDIP.ahk
#Include Gdip_ImageSearch.ahk
StopVar := 0
Return
;=============================================================
F12::
While ( !StopVar && !CustomImgSearch(Output1,Output2,0,0,A_ScreenWidth,A_ScreenHeight,"IMG/T-001-folder.png") )
{
ToolTip, % "Iteration " ( MyCounter := A_Index )
Sleep, 100
}
tooltip
MSGBOX % ( StopVar ? "Stopped by user." : "Couldn't find the needle on screen." ) "`nLast iteration: " MyCounter
ExitApp
;=============================================================
ESC:: StopVar := 1
;=============================================================
CustomImgSearch(ByRef out1, ByRef out2, x1, y1, x2, y2, image, vari=0, trans="",direction=5) {
token := Gdip_Startup()
needle := Gdip_CreateBitmapFromFile(image)
haystack := Gdip_Bitmapfromscreen(x1 "|" y1 "|" x2 - x1 "|" y2 - y1)
found := Gdip_ImageSearch(haystack,needle,tempxy,0,0,0,0,vari,trans,direction)
if !( found < 1 ) ; if successful
{
out:=StrSplit(tempxy,"`,")
out1:=out[1] + x1
out2:=out[2] + y1
}
Gdip_DisposeImage(haystack)
Gdip_DisposeImage(needle)
Gdip_Shutdown(token)
return ( found < 1 ) ; will return 0 for SUCCESS, 1 for FAILURE
}
Press F12 to begin. It will stop if you press ESC or if the needle cannot be found.
In my case, I left Explorer open and my test needle image was a folder icon.