HRESULT hr;
// get display dimensions
D3DDISPLAYMODE mode;
if (FAILED(hr=pDev-> GetDisplayMode(0,&mode))) return hr;
// create the image surface to store the front buffer image
LPDIRECT3DSURFACE9 surf;
if (FAILED(hr=pDev->CreateOffscreenPlainSurface(mode.Width,mode.Height,D3DFMT_A8R8G8B8,D3DPOOL_SYSTEMMEM,&surf,NULL)))
return hr;
// 第一个参数为0表示获取后台数据,也正是我想要的. -1 表示获取的是前台的数据..
if (FAILED(hr=pDev->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_FORCE_DWORD,&surf))) {
surf-> Release();
return hr;
}
// write the entire surface to the requested file
hr=D3DXSaveSurfaceToFile(fileName,D3DXIFF_JPG,surf,NULL,NULL);
// release the image surface
surf-> Release();
// return status of save operation to caller
return hr;