AutoHotkey-GDIp:从硬件加速窗口捕获屏幕截图 [英] AutoHotkey-GDIp: Capture a screenshot from a hardware accelerated window

查看:964
本文介绍了AutoHotkey-GDIp:从硬件加速窗口捕获屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究一个小的脚本,该脚本从BlueStacks中的硬件加速窗口捕获屏幕截图.

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.

我正在使用AutoHotkey进行脚本编写,并添加了用于访问GDI +的GDIp库.

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

我怀疑问题是由于软件将帧直接推到GPU上,GDIp无法使用PrintWindow捕获数据,但是必须有一种捕获该帧的方法.

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.

我的脚本:

#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 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.

推荐答案

我也在寻找解决方案.无论如何,我用另一种方式写它:

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)

它并不优雅,但是可以工作. 可能有一种自动设置clientW和clientH的简便方法,但是如果您的客户区大小固定(大多数情况下),这会更快-无需进行额外的计算.

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.

这篇关于AutoHotkey-GDIp:从硬件加速窗口捕获屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆