0
AM試圖在VS 2008中使用DirectX進行屏幕截圖。但總是我用來獲取黑色圖像。有人能指出我出去,什麼我的代碼錯誤的發生..我的代碼片段看起來是這樣的:無法使用DirectX捕獲屏幕
void CaptureScreen()
{
IDirect3DDevice9* pDirect3DDevice;
IDirect3DSurface9* pRenderTarget=NULL;
IDirect3DSurface9* pDestTarget=NULL;
D3DDISPLAYMODE d3ddisplaymode;
D3DPRESENT_PARAMETERS PresentParams;
memset(&PresentParams, 0, sizeof(D3DPRESENT_PARAMETERS));
PresentParams.Windowed = TRUE;
PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
HWND h = ::FindWindow(0,"EIML");
IDirect3D9* direct=Direct3DCreate9(D3D9b_SDK_VERSION);
direct->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
h,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&PresentParams,&pDirect3DDevice);
if (pDirect3DDevice == NULL)
return;
HRESULT hr = pDirect3DDevice->GetRenderTarget(0, &pRenderTarget);
hr = direct->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3ddisplaymode);
hr = pDirect3DDevice->CreateOffscreenPlainSurface(d3ddisplaymode.Width,d3ddisplaymode.Height,D3DFMT_A8R8G8B8,
D3DPOOL_SYSTEMMEM,
&pDestTarget,
NULL);
pDirect3DDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pDestTarget) ;
hr = pDirect3DDevice->GetRenderTargetData(pRenderTarget,pDestTarget);
hr = D3DXSaveSurfaceToFile("C:\\Image1.bmp",
D3DXIFF_BMP,
pDestTarget,
NULL,
NULL);
pRenderTarget->Release();
pDestTarget->Release();
}
謝謝。
喜即使我正在嘗試使用directx捕獲backbuffer的屏幕截圖。您可以請我幫助我一個MCVE或重定向到一個示例調試代碼,我可以嘗試使用'GetBackBuffer'來捕獲桌面屏幕截圖。 – newbie2015 2015-09-27 19:25:20