Gdip_BitmapFromHWND capture problem when reading from Emulator window

Get help with using AutoHotkey and its commands and hotkeys
+MeleaB+
Posts: 11
Joined: 26 Oct 2017, 18:46

Gdip_BitmapFromHWND capture problem when reading from Emulator window

28 Nov 2017, 18:04

Hello.

I've written a program that uses Gdip_BitmapFromHWND to create a bitmap from which I test for certain pixel colours. On my desktop it works fine, including- most importantly- on the MOMO Android emulator on which it is used in order to read pixels from a game.

However, on my laptop and for others, although it can capture the images of other [non-emulator] windows (Notepad, Paint etc) it has a problem with the image from the emulator. Instead of the image that is visible on the screen, it returns an image which is displayed during the start-up of the emulator.

I've spent hours trying to learn/research and discover the problem, but so far to no avail. I thought it may be a DirectX v OpenGL rendering issue, but I've since learned that the MOMO emulator doesn't yet support DiectX. The emulator uses a VirtualBox headless environment (if that's the current terminology) and so I wondered if the problem lay there. (I've read some people have had problems with VirtualBox getting the inbuilt SnapShot funcction working- an issue that goes back years from what I see.)

I used this simplified piece of code (shown below) to test the images found from capturing the displays of various windows, to see if the emulator image was read correctly. In running it I also found that I wasn't able to capture the screen of Google Chrome windows- just a black screen and a title bar appeared. (I don't need to read form Google Chrome but I'm just noting that it also wasn't read in case it is related.)

I know I can use Gdip_BitmapFromScreen, and that works as it's supposed to, but it's far less suitable for my needs (as I need to read hidden, or partly obscured, windows.) I've found a couple of similar AHK questions related to capturing images from Android emulators but with no definitive solution. If what I need just couldn't be achieved then I'd say "fair enough' and look at the next best solution, but the fact that it works perfectly on my setup makes it's all the more frustrating.

I would be most grateful for any help that anyone could offer. Thanks!


Code: Select all

#SingleInstance Force
#include <gdip>
#NoEnv
SetBatchLines, -1
SetTitleMatchMode, RegEx
SetTitleMatchMode, slow


pToken := gdip_startup()
file=%a_scriptdir%\thumbnail.png

Gui, +Caption +Border +E0x08000000
Gui, Add, Picture, vthumbnail
Gui, Show, x100 y100 w200 h200, image

f1::
WinGet, WinID ,, A
WinGetPos,,, w, h, % "ahk_id " WinID
pBitmap := Gdip_BitmapFromHWND(WinID)
Gdip_SaveBitmapToFile(pBitmap,file)
Gdip_DisposeImage(pBitmap)
guicontrol,,thumbnail, *w%w% *h%h% thumbnail.png
Gui, Show, x100 y100 w%w% h%h%, image
return

GuiClose:
Gdip_Shutdown(pToken)
ExitApp
User avatar
Blackholyman
Posts: 1282
Joined: 29 Sep 2013, 22:57
Facebook: socialjsz
Google: +Jszapp
Location: Denmark
Contact:

Re: Gdip_BitmapFromHWND capture problem when reading from Emulator window

29 Nov 2017, 08:39

Gdip_BitmapFromHWND uses PrintWindow()

and Gdip_BitmapFromScreen uses BitBlt

this may help https://stackoverflow.com/questions/306 ... w-is-blank
A_User
Posts: 36
Joined: 21 Aug 2017, 01:15

Re: Gdip_BitmapFromHWND capture problem when reading from Emulator window

29 Nov 2017, 11:01

Sounds like an OpenGL specific issue. If you search the web with keywords like "capture OpenGL window" or "OpenGL screenshot", you'll find relevant information and workarounds written in other languages. At the moment, I don't find a good solution with AutoHotkey.
+MeleaB+
Posts: 11
Joined: 26 Oct 2017, 18:46

Re: Gdip_BitmapFromHWND capture problem when reading from Emulator window

30 Nov 2017, 20:34

Blackholyman wrote:Gdip_BitmapFromHWND uses PrintWindow()

and Gdip_BitmapFromScreen uses BitBlt

this may help https://stackoverflow.com/questions/306 ... w-is-blank
A_User wrote:Sounds like an OpenGL specific issue. If you search the web with keywords like "capture OpenGL window" or "OpenGL screenshot", you'll find relevant information and workarounds written in other languages. At the moment, I don't find a good solution with AutoHotkey.
Thanks guy. I'll continue with my research per your suggestions.

The fact that it *does* work on my desktop but not on my laptop (or with some other users) makes this more of a mystery to me though. Would that not rule out a lot of suggestions, such as DirectX v OpenGL, simply because it is actually working in, at least, one instance?
+MeleaB+
Posts: 11
Joined: 26 Oct 2017, 18:46

Re: Gdip_BitmapFromHWND capture problem when reading from Emulator window

30 Nov 2017, 21:04

A_User wrote:Sounds like an OpenGL specific issue. If you search the web with keywords like "capture OpenGL window" or "OpenGL screenshot", you'll find relevant information and workarounds written in other languages. At the moment, I don't find a good solution with AutoHotkey.
Presumably though, if OpenGL was the issue, and if I could find a non-AHK solution to capture a Bitmap screenshot, then I could execute that program from AHK and then use AHK to manipulate that screenshot?
herqliz
Posts: 2
Joined: 09 Jan 2018, 10:07

Re: Gdip_BitmapFromHWND capture problem when reading from Emulator window

09 Jan 2018, 10:11

I also face same problem. PC work fine but 2 laptop has a problem
- Gdip_BitmapFromScreen ... can get refresh screen properly
- Gdip_BitmapFromHWND ... it show screen before boot to Game (I use Nox Emulator with DirectX configured) and not get any refresh
herqliz
Posts: 2
Joined: 09 Jan 2018, 10:07

Re: Gdip_BitmapFromHWND capture problem when reading from Emulator window

09 Jan 2018, 22:37

moreover using Gdip_BigmapFromScreen("hwnd:" hwnd) also get an issue

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], cabbagethunder, cadudesun, flyingDman, jbullock35, Lorien, Rohwedder and 236 guests