2

I am currently working on a small script which captures a screenshot from a hardware accelerated window in BlueStacks.

Problem is, that it appears the window must be hardware accelerated, so the screen capture is saving a black square.

I am using AutoHotkey for my scripting, and have added the GDIp libraries for access to GDI+.

I suspect the problem is that GDIp cannot grab the data using PrintWindow due to the software pushing the frame directly to the GPU, but there must be a way to capture this frame.

My script:

#SingleInstance, Force
#NoEnv
SetBatchLines, -1
OnExit, Exit

#Include Gdip.ahk
#Include GDIpHelper.ahk

SetUpGDIP()

WinGet, hwnd, ID, BlueStacks App Player

pBitmap := Gdip_BitmapFromHWND(hwnd)

Gdip_SaveBitmapToFile(pBitmap, "TestOutput.png", 100)

Gdip_DisposeImage(pBitmap)

return

The actual screen to capture:

Manual Screenshot done with Alt+PrtScrn

The actual file output by my script: Black square, proper dimensions so it's seeing the right thing, but can't get the pixel data

Any ideas on where to go or any kind of instruction on how to access the framebuffer perhaps? It can't be something no one has needed to do before.

MaurerPower
  • 2,046
  • 7
  • 26
  • 48
  • it works for me without gdi+, I do really with I could use gdi+ but it doesn't seem to work – Alice Nov 07 '16 at 05:41

1 Answers1

1

I'm looking for a solution too. Anyway, I wrote it in another way:

pToken := Gdip_Startup()
winName := "BlueStacks App Player"
clientW := 868 ; set your client area width
clientH := 720 ; set your client area height
WinGetPos, x, y, w, h, %winName%
winBorder := (w-clientW)/2
x := x+winBorder
y := y+(h-clientH-winBorder)
snap := Gdip_BitmapFromScreen(x "|" y "|" clientW "|" clientH)
Gdip_SaveBitmapToFile(snap, "snap.png")
Gdip_DisposeImage(snap)
Gdip_ShutDown(pToken)

It's not elegant but works. Probably there is an easy way to set clientW and clientH automaticly, but if your client area has fixed size (most cases) this is faster - no extra calculations.

kapitalny
  • 310
  • 4
  • 7