in v1, im := ImagePutBuffer({screenshot: "A", crop: [100, 100, -100, -100]}) was return with error. I update ImagePut.ahk from github. Now has no error.
Im now testing in .ahk I couldnt pass .exe yet. I need a working methot for both. @Ahk2Exe allows to put images in .exe file, so you can call images with variable example; ImageSearch, XE, YE, 31,35, 110,100, *TransWhite *2 HBITMAP:*%HTestImageFound% ; this method is slow, recapture screen for every search. As you mention, I need to put captured image in buffer and compare with other bitmaps.
Code: Select all
F1::
ix := 300 ; example
gosub, activatebmp
buf := ImagePutBuffer({screenshot: "A", crop: [iX-234,35, 210,960]}) ; working flawless
; ImageShow(buf) ; checked image, it gets right image from ImagePutBuffer.
; add and test 2 image. TestImageFound.bmp and TestImageNot.bmp
target := ImagePutBuffer("C:\Bitmaplib\TestImageFound.bmp") ; it returns not found and checked ImageShow(target) it shows image well.
target := ImagePutBuffer("C:\Bitmaplib\TestImageNot.bmp") ; it returns not found and checked ImageShow(target) it shows image well.
; --------------------------------
target := ImagePutBuffer("TestImageFound.bmp") ; it returns "Imagetype could not be identified" image file is not in workingdir.
target := ImagePutBuffer("TestImageNot.bmp") ; it returns "Imagetype could not be identified" image file is not in workingdir.
; --------------------------------
target := ImagePutBuffer(LoadBitmapResource("TestImageFound.bmp")) ; (in .ahk) returns "could not load bitmap" as expected. (in .exe) returns not found and checked ImageShow(target) it shows image well.
target := ImagePutBuffer(LoadBitmapResource("TestImageNot.bmp")) ; (in .ahk) returns "could not load bitmap" as expected. (in .exe) returns not found and checked ImageShow(target) it shows image well.
; --------------------------------
target := ImagePutBuffer(LoadPicture("C:\Bitmaplib\TestImageFound.bmp")) ; it returns found and checked ImageShow(target) it shows nothing.
target := ImagePutBuffer(LoadPicture("C:\Bitmaplib\TestImageNot.bmp")) ; it returns found and checked ImageShow(target) it shows nothing.
; --------------------------------
target := ImagePutBuffer(HTestImageFound) ; it returns found and checked ImageShow(target) it shows nothing.
target := ImagePutBuffer(HTestImageNot) ; it returns found and checked ImageShow(target) it shows nothing.
; --------------------------------
if xy := buf.ImageSearch(target) ; also tried if (xy := buf.ImageSearch(target))
{
msgbox, found
}else{
msgbox, not found
}
; --------------------------------
return
activatebmp:
;@Ahk2Exe-IgnoreBegin
HTestImage := LoadPicture("C:\Bitmaplib\TestImageFound.bmp")
HTestImage := LoadPicture("C:\Bitmaplib\TestImageNot.bmp")
return
;@Ahk2Exe-IgnoreEnd
;@Ahk2Exe-AddResource C:\Bitmaplib\TestImageFound.bmp
;@Ahk2Exe-AddResource C:\Bitmaplib\TestImageNot.bmp
HTestImage:= LoadBitmapResource("TestImageFound.bmp")
HTestImage:= LoadBitmapResource("TestImageNot.bmp")
return
I also add LoadBitmapResource, it may help.
LoadBitmapResource and LoadPicture returns in same variable and output same type. So, imagesearch can search HBITMAP:*%HTestImage% even in (.ahk) or (.exe)
Code: Select all
LoadBitmapResource(resName, shared := true)
{
resNameType := "str"
if resName is integer
if resName between 0 and 0xFFFF
resNameType := "ptr"
if not ret := DllCall("LoadImage", "ptr", GetOwnModuleHandle(), resNameType, resName, "uint", 0, "int", 0, "int", 0, "uint", shared ? 0x8000 : 0, "ptr")
throw Exception("Could not load bitmap!", -1, "resName: " resName " - ErrLvl: " ErrorLevel " - LastErr: " A_LastError)
return ret
}