gpt4 book ai didi

c++ - 截图 C++ directx 获取黑色图像

转载 作者:行者123 更新时间:2023-11-30 00:58:15 25 4
gpt4 key购买 nike

我正在尝试使用 directx 进行屏幕截图。我尝试了几个页面中的代码,这些代码解释了如何但总是得到一个黑屏截图。如果有人能帮助我,我将不胜感激。

我的代码是:

int _tmain(int argc, _TCHAR* argv[])
{
IDirect3DDevice9* g_pd3dDevice;
//SaveScreenShot("test.bmp",D3DXIFF_BMP);
IDirect3DSurface9* pSurface=NULL;
//IDirect3DSurface9* pSource=NULL;
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = FALSE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferWidth = 1280;
d3dpp.BackBufferHeight = 1024;
d3dpp.hDeviceWindow = GetDesktopWindow();
d3dpp.FullScreen_RefreshRateInHz=0;
d3dpp.MultiSampleQuality=0;
IDirect3D9* direct=Direct3DCreate9(D3D9b_SDK_VERSION);
direct->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
GetDesktopWindow(),
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,&g_pd3dDevice);


//g_pd3dDevice->GetRenderTarget(0,&pSource);
g_pd3dDevice->CreateOffscreenPlainSurface(1280, 1024,
D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &pSurface, NULL);
g_pd3dDevice->GetFrontBufferData(0, pSurface);
/*g_pd3dDevice->GetRenderTargetData(pSource,pSurface);
g_pd3dDevice->GetRenderTargetData(pSource,pSurface);*/
D3DXSaveSurfaceToFile("Desktop.jpg",D3DXIFF_JPG,pSurface,NULL,NULL);
pSurface->Release();
//pSource->Release();
return 0;
}

最佳答案

尝试添加一些错误处理,也许您会知道失败的原因。

关于c++ - 截图 C++ directx 获取黑色图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6718524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com