我想为Windows平台编写一个截屏程序,但我不确定如何捕获屏幕.我所知道的唯一方法就是使用GDI,但我很好奇是否还有其他方法可以解决这个问题,如果有的话,会产生最少的开销?速度是一个优先事项.
屏幕录像程序将用于录制游戏镜头,但是,如果这确实缩小了选项范围,我仍然可以接受任何其他超出此范围的建议.毕竟知识还不错.
编辑:我遇到过这篇文章:Various methods for capturing the screen.它向我介绍了Windows Media API的实现方式以及DirectX的实现方式.它在结论中提到,禁用硬件加速可以极大地提高捕获应用程序的性能.我很好奇为什么会这样.任何人都可以为我填补遗失的空白吗?
编辑:我读过像Camtasia这样的截屏程序使用他们自己的捕获驱动程序.有人能给我一个深入的解释它是如何工作的,以及为什么它更快?我可能还需要有关实现此类内容的指导,但我确信无论如何都有现有的文档.
此外,我现在知道FRAPS如何记录屏幕.它挂钩底层图形API以从后台缓冲区读取.根据我的理解,这比从前端缓冲区读取更快,因为您是从系统RAM而不是视频RAM读取的.你可以阅读文章here.
解决方法:
这是我用来收集单帧的内容,但是如果你修改它并保持两个目标一直打开,那么你可以使用文件名的静态计数器将它“流”到磁盘. – 我不记得我在哪里发现了这个,但它已被修改,多亏了谁!
void dump_buffer()
{
IDirect3DSurface9* prendertarget=NULL;
IDirect3DSurface9* pDestTarget=NULL;
const char file[] = "Pickture.bmp";
// sanity checks.
if (Device == NULL)
return;
// get the render target surface.
HRESULT hr = Device->Getrendertarget(0, &prendertarget);
// get the current adapter display mode.
//hr = pDirect3D->GetAdapterdisplayMode(D3DADAPTER_DEFAULT,&d3ddisplaymode);
// create a destination surface.
hr = Device->CreateOffscreenPlainSurface(displayMde.Width,
displayMde.Height,
displayMde.Format,
D3DPOOL_SYstemMEM,
&pDestTarget,
NULL);
//copy the render target to the destination surface.
hr = Device->GetrendertargetData(prendertarget, pDestTarget);
//save its contents to a bitmap file.
hr = D3DXSaveSurfacetoFile(file,
D3DXIFF_BMP,
pDestTarget,
NULL,
NULL);
// clean up.
prendertarget->Release();
pDestTarget->Release();
}