AutoHotkey-GDIp: Capture a screenshot from a hardware accelerated window

北战南征 提交于 2019-12-08 05:01:10

问题


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:

The actual file output by my script:

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.


回答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.



来源:https://stackoverflow.com/questions/29245949/autohotkey-gdip-capture-a-screenshot-from-a-hardware-accelerated-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!