Page 1 of 1

But ImageSearch of ScreenPrint Works!

Posted: 23 Jan 2019, 16:29
by kkleinfelter
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?

Re: But ImageSearch of ScreenPrint Works!

Posted: 23 Jan 2019, 19:07
by SL5

Re: But ImageSearch of ScreenPrint Works!

Posted: 23 Jan 2019, 19:14
by Xtra
When you check ErrorLevel is it 1 or 2 ?

Re: But ImageSearch of ScreenPrint Works!

Posted: 24 Jan 2019, 13:30
by kkleinfelter
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.'

Re: But ImageSearch of ScreenPrint Works!

Posted: 24 Jan 2019, 13:38
by kkleinfelter
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!

Re: But ImageSearch of ScreenPrint Works!

Posted: 24 Jan 2019, 17:51
by SL5
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/ ?

Re: But ImageSearch of ScreenPrint Works!

Posted: 24 Jan 2019, 18:09
by Hellbent
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?

Re: But ImageSearch of ScreenPrint Works!

Posted: 24 Jan 2019, 19:20
by Xtra

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

Re: But ImageSearch of ScreenPrint Works!

Posted: 26 Jan 2019, 16:08
by kkleinfelter
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!