我知道如何使用GDI来捕获屏幕,但它非常慢(几乎只能捕获10帧每秒)。
我已经读到DirectX提供了最佳速度,但在我开始学习DirectX之前,我想测试一下样例,看看它是否真的那么快。
我找到了这个问题,提供了一个示例代码来实现:
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();
}
我已经尝试包含所需的文件,但并非所有文件都可以被包含(例如#include <D3dx9tex.h>
)。
有人能否提供一个具有所有必需的包含文件的可行示例,或者指导我应该安装哪些库。
我正在使用 Windows 7 Ultimate (x64) 上的 Visual C++ 2010 Express。
编辑:
此外,这段代码不完整,例如Device
标识符是什么?!
#include <D3D9.h>
,是因为我安装了旧版本的DirectX SDK吗? - user4592590