比较简单, 下面直接贴代码了:
// 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();