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