8

多平台下录屏方式 - Skywind Inside

 3 years ago
source link: https://www.skywind.me/blog/archives/1564
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

多平台下录屏方式

随便记录下,想得起来的多少写多少:

Windows:
GDI 全屏:fullscreen desktop BitBlt 速度是 20ms / 帧
GDI 窗口:Win7+可以录制游戏和非游戏,XP以前只能录制普通界面,截不到游戏窗口
DirectDraw 全屏:full screen primary surface 异步到 offscreen-surface XP下闪电速度 1ms / 帧
D3D9: render target -> offscreen surface XP下 16ms Win7 下 10ms
D3D Hook: Hook Device::Present -> 保存 StateBlock -> 截屏 -> 恢复 StateBlock 极速!

Linux:
framebuffer: 打开 /dev/fb0 映射到内存,直接读里面内容,部分显卡驱动启用硬件加速绘图后,framebuffer会被跳过,直接调用 framebuffer 导致读取出来的东西为空。

Android:
framebuffer: 需要 root 权限才能访问 framebuffer
RootView: 取得 root view 然后得到 drawing cache 然后保存,兼容性好,慢。
OpenGL:直接 glReadPixel 保险,但是会卡到应用。
OpenGL FBO: 更改渲染的 FBO ,让渲染到纹理,从纹理取下来,还行,速度还好。
screenshot: SurfaceComposerClient::getBuiltInDisplay Android 4.0 以后,性能不错。
native buffer: ANativeWindowBuffer -> GraphicBuffer -> 映射读取, 性能不错

iOS:
OpenGL: 直接 glReadPixel 同 Android,同样会卡到应用
OpenGL FBO: 渲染到 FBO,读取下来,还行。

大部分方法可以用 Hook 的方式注入到目标程序,或者系统 API,在不需要目标程序改一行代码的情况下实现功能。

331 total views, 2 views today

I like thisUnlike LikeI dislike thisUndislike 


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK