Use GDI+ to do image search?

Get help with using AutoHotkey and its commands and hotkeys
980322091
Posts: 10
Joined: 15 Feb 2017, 12:17

Use GDI+ to do image search?

05 Mar 2017, 23:46

I am using ImageSearch to search a bitmap image in a loop, however it causes my screen lag sometimes. I did some research and found out that I can use GDI+ instead, I just got into ahk and never heard of GDI+, can someone give me a example how it works? and maybe offer me some useful link? Thanks.
980322091
Posts: 10
Joined: 15 Feb 2017, 12:17

Re: Use GDI+ to do image search?

06 Mar 2017, 14:43

I still need help please.
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Use GDI+ to do image search?

08 Mar 2017, 23:54

This is actually pretty fiddly if you're new to Gdip.ahk/Gdip_All.ahk. Plus you need to include an add-on script: Gdip_ImageSearch.ahk.
HTH

Code: Select all

;put Gdip.ahk (or Gdip_All.ahk) and Gdip_ImageSearch.ahk into:
;C:\Program Files\AutoHotkey\Lib

;at GitHub, right-click the Raw button to save the ahk file
;Gdip/Gdip.ahk at master · tariqporter/Gdip · GitHub
;https://github.com/tariqporter/Gdip/blob/master/Gdip.ahk
;Gdip_All.ahk
;https://www.dropbox.com/s/0e9gdfetbfa8v0o/Gdip_All.ahk
;AutoHotkey/Gdip_ImageSearch.ahk at master · MasterFocus/AutoHotkey · GitHub
;https://github.com/MasterFocus/AutoHotkey/blob/master/Functions/Gdip_ImageSearch/Gdip_ImageSearch.ahk

;an example of a regular ImageSearch:
;My first project: How hard/easy it is to develop a script for this? - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?p=131491#p131491

q::
vPathN := A_Desktop "\MyNeedleImage.png"
vPathH := A_Desktop "\MyHaystackImage.png"

vScreen1 := 0
vScreen2 := 0
vScreen3 := A_ScreenWidth
vScreen4 := A_ScreenHeight
vScreen := vScreen1 "|" vScreen2 "|" vScreen3 "|" vScreen4
vPos1 := 0, vPos2 := 0, vPos3 := vScreen3, vPos4 := vScreen4

pToken := Gdip_Startup()
vMode := "s"
;vMode := "f"
if (vMode = "s") ;haystack is screen
	pBitmapH := Gdip_BitmapFromScreen(vScreen, 0x40CC0020)
if (vMode = "f") ;haystack is another image
{
	pBitmapH := Gdip_CreateBitmapFromFile(vPathH)
	Gdip_GetDimensions(pBitmapH, vPos3, vPos4)
	MsgBox, % vPos3 " " vPos4
}
pBitmapN := Gdip_CreateBitmapFromFile(vPathN)
;vRet: 0=not found, 1=found
vRet := Gdip_ImageSearch(pBitmapH, pBitmapN, vPosXY, vPos1, vPos2, vPos3, vPos4)
vPos := InStr(vPosXY, ",")
vPosX := SubStr(vPosXY, 1, vPos-1)
vPosY := SubStr(vPosXY, vPos+1)
Gdip_DisposeImage(pBitmapH)
Gdip_DisposeImage(pBitmapN)
Gdip_Shutdown(pToken)
MsgBox, % vRet " (" vPosXY ")"
;MsgBox, % vPosX " " vPosY
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], BreezeB, Google [Bot], kai, MSN [Bot], scriptor2016 and 203 guests