|
这是我找到的代码,是8.1的
void TakeScreenShot(IDirect3DDevice8* device, char* file_name, int screenx, int screeny)
{
IDirect3DSurface8* frontbuf; //this is our pointer to the memory location containing our copy of the
//front buffer
//now we create the image that our screen shot will be copied into
//NOTE: Surface format of the front buffer is D3DFMT_A8R8G8B8 when it is returned
device->CreateImageSurface(screenx, screeny, D3DFMT_A8R8G8B8, &frontbuf);
//now we copy the front buffer into our surface
HRESULT hr = device->GetFrontBuffer(frontbuf);
//error checking
if(hr != D3D_OK)
{
//do error handling etc...
frontbuf->Release(); //release the surface so there is no memory leak
return;
}
//now write our screen shot to a bitmap file
//the last 2 params are NULL because we want the entire front buffer and no palette
D3DXSaveSurfaceToFile(file_name, D3DXIFF_BMP, frontbuf, NULL, NULL);
//release the surface so there is no memory leak
frontbuf->Release();
}
不过我的是9.0的。有些函数的参数改变了。
HRESULT ScreenGrab(IDirect3DDevice9* pDev,LPCWSTR fileName)
{
HRESULT hr;
// get display dimensions
// this will be the dimensions of the front buffer
D3DDISPLAYMODE mode;
UINT iSwapChain = 0;
if (FAILED(hr=pDev->GetDisplayMode(iSwapChain,&mode)))
return hr;
// create the image surface to store the front buffer image
// note that call to GetFrontBuffer will always convert format to A8R8G8B8
LPDIRECT3DSURFACE9 surf;
if (FAILED(hr=pDev->CreateRenderTarget(mode.Width,mode.Height,
D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE , 0, false, &surf ,NULL)))
return hr;
//pDev->CreateDepthStencilSurface
//pDev->
//Next, this surface is passed to the GetFrontBuffer() method of the device, which will copy the entire screen into our image buffer:
// read the front buffer into the image surface
hr=pDev->GetFrontBufferData(iSwapChain,surf);
if ( FAILED(hr=pDev->GetFrontBufferData(iSwapChain,surf)))
{
surf->Release();
return hr;
}
//Finally, we call D3DXSaveSurfaceToFile() to create the BMP file, and release the temporary image surface:
// write the entire surface to the requested file
hr=D3DXSaveSurfaceToFile(L"g.jpg",D3DXIFF_JPG,surf,NULL,NULL);
// release the image surface
surf->Release();
// return status of save operation to caller
return hr;
}
不过最后没有保存出任何一个JPG的文件。请问这个函数在那里失败了。是我在9.0下面的参数错了吗?
谁有相关的程序或者方法请指导一下。谢谢啊
|
|