RESULT IS: FOUND
Code: Select all
#include ImagePut (for v1).ahk
#singleinstance force
; Get a random image.
pic := ImagePutBuffer("C:\Macrolarım\aaBitmaplib\T1_Test_Image2.bmp")
; Get random coordinates.
Random, x, 0, % pic.width
loop
Random, x2, 0, % pic.width
until x2 != x
Random, y, 0, % pic.height
loop
Random, y2, 0, % pic.height
until y2 != y
; Crop the source image to create a random search image.
search := pic.crop(min(x, x2), min(y, y2), abs(x2 - x), abs(y2 - y))
; Optional: Make all white pixels transparent.
; Doing so allows searching of non-rectangular images.
; search.transcolor(0xFFFFFF) ; if activate this line, and if image has transcolor, RESULT IS NOT FOUND
search2 := ImagePutHBitmap(search)
; Find the cropped image.
xy := pic.imagesearch(search2)
; hwnd := pic.show()
; If found, create a box around it. RESULT IS FOUND
if (xy)
{
msgbox % "yes"
MouseMove xy[1], xy[2]
WinGetPos wx, wy,,, % "ahk_id" hwnd
search.show(1, "", [wx+xy[1], wy+xy[2]])
}else{
msgbox % "no"
search.show(1, "Not Found", [A_ScreenWidth//2 - 600])
}
return
if search2 has transcolor RESULT IS: NOT FOUND else RESULT IS: FOUND
Code: Select all
#include ImagePut (for v1).ahk
#singleinstance force
; Get a random image.
pic := ImagePutBuffer("C:\Macrolarım\aaBitmaplib\T1_Test_Image2.bmp")
; Get random coordinates.
Random, x, 0, % pic.width
loop
Random, x2, 0, % pic.width
until x2 != x
Random, y, 0, % pic.height
loop
Random, y2, 0, % pic.height
until y2 != y
; Crop the source image to create a random search image.
search := pic.crop(min(x, x2), min(y, y2), abs(x2 - x), abs(y2 - y))
; Optional: Make all white pixels transparent.
; Doing so allows searching of non-rectangular images.
search.transcolor(0xFFFFFF)
search2 := ImagePutHBitmap(search)
; get screenshot
pic := ImagePutBuffer([0, 0, 1920, 972, "A"])
; Find the cropped image.
xy := pic.imagesearch(search2)
; hwnd := pic.show()
; If found, create a box around it. if search2 has transcolor RESULT IS NOT FOUND else RESULT IS FOUND
if (xy)
{
msgbox % "yes"
MouseMove xy[1], xy[2]
WinGetPos wx, wy,,, % "ahk_id" hwnd
search.show(1, "", [wx+xy[1], wy+xy[2]])
}else{
msgbox % "no"
search.show(1, "Not Found", [A_ScreenWidth//2 - 600])
}
return
conclusion; imagesearch doesnt work work with (if) search.transcolor(0xFFFFFF)
All my test, I couldnt manage to find any transcolored image.