But ImageSearch of ScreenPrint Works!

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kkleinfelter
Posts: 32
Joined: 21 Dec 2018, 10:59

But ImageSearch of ScreenPrint Works!

23 Jan 2019, 16:29

I run an ImageSearch with an image plainly visible on the screen, and ImageSearch fails to find it. OK. I must be doing it wrong.

But, I can screenprint that same visible image and paste it into MS Paint, and the same Imagesearch finds it.

Code: Select all

    CoordMode, Pixel, Screen
    CoordMode, Mouse, Screen
    Image = e:\autohotkey\search-images\Webex-Button.bmp
    ImageSearch, FoundX, FoundY, 0, 0, 1920, 1080, *20 %Image%
I'm trying to wait for the WebEx "Connect Audio" button to appear. I saved a captured image of this button to e:\autohotkey\search-images\Webex-Button.bmp. When WebEx shows the button, the code cannot find it on the screen, but it CAN find it in a spreenprint of the screen.

What am I missing?
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: But ImageSearch of ScreenPrint Works!

23 Jan 2019, 19:14

When you check ErrorLevel is it 1 or 2 ?
kkleinfelter
Posts: 32
Joined: 21 Dec 2018, 10:59

Re: But ImageSearch of ScreenPrint Works!

24 Jan 2019, 13:30

OK. This is really weird. I switched to using GDIP. The search call looks like this:

Code: Select all

RET := Gdip_ImageSearch(bmpHaystack,bmpNeedle,LIST, 0,0,hWidth,hHeight)
If I set bmpHaystack with this code:

Code: Select all

send ^{PrintScreen}
bmpHaystack := Gdip_CreateBitmapFromClipboard()
it finds the image successfully. But if I set bmpHaysack with the following code, it fails:

Code: Select all

bmpHaystack := Gdip_BitmapFromScreen()
Here's the complete working code. I'd like to un-comment the commented line, but when I do, the search fails.

Code: Select all

p := Gdip_Startup()
Image = e:\autohotkey\search-images\conference-join.png
bmpNeedle := Gdip_CreateBitmapFromFile(Image)

send ^{PrintScreen}
bmpHaystack := Gdip_CreateBitmapFromClipboard()

;bmpHaystack := Gdip_BitmapFromScreen()

Gdip_GetImageDimensions(bmpHaystack,hWidth,hHeight)
RET := Gdip_ImageSearch(bmpHaystack,bmpNeedle,LIST, 0,0,hWidth,hHeight)

MsgBox, RET is %RET%
    
Gdip_Shutdown(p)
#include e:\autohotkey\scripts\gdip.ahk
#include e:\autohotkey\scripts\Gdip_ImageSearch.ahk
In this case, 'fails' means 'returns zero instead of 1.'
kkleinfelter
Posts: 32
Joined: 21 Dec 2018, 10:59

Re: But ImageSearch of ScreenPrint Works!

24 Jan 2019, 13:38

I saved the PrintScreen bitmap and the Gdip_BitmapFromScreen bitmap to disk. The PrintScreen image shows the screen as I see it on the monitor. The Gdip image is missing the entire window of interest. The window is simply invisible to Gdip!
User avatar
SL5
Posts: 879
Joined: 12 May 2015, 02:10
Contact:

Re: But ImageSearch of ScreenPrint Works!

24 Jan 2019, 17:51

kkleinfelter wrote:
24 Jan 2019, 13:38
I saved the PrintScreen bitmap and the Gdip_BitmapFromScreen bitmap to disk. The PrintScreen image shows the screen as I see it on the monitor. The Gdip image is missing the entire window of interest. The window is simply invisible to Gdip!
thats interessting. looks realy difficult then.

maybe you try a few other tools to create a screenshot.

what about http://getgreenshot.org/ ?
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: But ImageSearch of ScreenPrint Works!

24 Jan 2019, 18:09

kkleinfelter wrote:
24 Jan 2019, 13:38
I saved the PrintScreen bitmap and the Gdip_BitmapFromScreen bitmap to disk. The PrintScreen image shows the screen as I see it on the monitor. The Gdip image is missing the entire window of interest. The window is simply invisible to Gdip!
Have you tried specifying a area of your screen with Gdip_BitmapFromScreen() to see if that yields anything?
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: But ImageSearch of ScreenPrint Works!

24 Jan 2019, 19:20

Code: Select all

bmpHaystack := Gdip_BitmapFromScreen(0 "|" 0 "|" A_ScreenWidth "|" A_ScreenHeight, 0x40000000 | 0x00CC0020)
The last parameter is Raster you need it to deal with layered windows.
You should also be checking if bmpHaystack contains the pointer and not blank. (Just like ErrorLevel with imagesearch command...)
HTH
kkleinfelter
Posts: 32
Joined: 21 Dec 2018, 10:59

Re: But ImageSearch of ScreenPrint Works!

26 Jan 2019, 16:08

CAPTUREBLT fixed it. (CAPTUREBLT = 0x00CC0020 | 0x40000000)

It's been a while since I did coding at the level of BitBlt. If I understand correctly, the simplified explanation amounts to
  • Gdip_BitmapFromScreen() will capture the whole screen if you have simple windows
  • Upgrade to Gdip_BitmapFromScreen(0, 0x40000000 | 0x00CC0020 ) if any windows use transparency
If there are any windows with the WS_EX_LAYERED attribute, you've got to use CAPTUREBLT to capture them.

Thanks!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: scriptor2016 and 136 guests