抓取 Direct3D 图像到 GDI 位图

比较简单, 下面直接贴代码了:

 

// IDirect3DDevice8* pDevice;
// RECT rcScreen; // = {0, 0, 1024, 768}; 
// HDC hdc;
// HBITMAP hbitmap;
// 忽略返回值检查,应该按需要加入错误处理

IDirect3DSurface8* pfb;
pDevice->CreateImageSurface(rcScreen.right, rcScreen.bottom, D3DFMT_A8R8G8B8, &pfb);
pDevice->GetFrontBuffer(pfb);

D3DLOCKED_RECT lr;
pfb->LockRect(&lr, NULL, D3DLOCK_READONLY);

BITMAPINFOHEADER bih;
memset(&bih, 0, sizeof(BITMAPINFOHEADER));
bih.biSize = sizeof(BITMAPINFOHEADER);
bih.biWidth = rcScreen.right;
bih.biHeight = rcScreen.bottom;
bih.biPlanes = 1;
bih.biBitCount = 32;
bih.biCompression = BI_RGB;

SetDIBits(hdc, hbitmap, 0, rcScreen.bottom, lr.pBits, &bih, DIB_RGB_COLORS);

pfb->UnlockRect();
pfb->Release();

 

上一篇:模拟信号量及 PV 原语的实现


下一篇:在 Win32 Application 中使用 MFC