我想通過使用「memcpy」函數將我的DirectX屏幕從backbuffer捕獲到內存地址。 ,所以我寫了這個代碼:Directx Backbuffer capture
int ScreenWidth =1024;
int ScreenHeight =768;
int BITSPERPIXEL =32; // XRGB
BYTE* pBits ;
IDirect3DSurface9* pSurface;
pBits=new BYTE[ScreenWidth*ScreenHeight * 4 ]; //1024 x 768 x 4 for XRGB
pd3dDevice->CreateOffscreenPlainSurface(ScreenWidth , ScreenHeight ,
D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM,
&pSurface, NULL);
pd3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE::D3DBACKBUFFER_TYPE_MONO, &pSurface);
D3DLOCKED_RECT lockedRect;
pSurface->LockRect(&lockedRect,NULL,
D3DLOCK_NO_DIRTY_UPDATE|
D3DLOCK_NOSYSLOCK|D3DLOCK_READONLY);
for(int i=0 ; i < ScreenHeight ; i++)
{
memcpy((BYTE*) pBits + i * ScreenWidth * BITSPERPIXEL/8 ,
(BYTE*) lockedRect.pBits + i* lockedRect.Pitch ,
ScreenWidth * BITSPERPIXEL/8);
}
pSurface->UnlockRect();
但是當程序運行我得到這個錯誤:
memcpy((BYTE*) pBits + i * ScreenWidth * BITSPERPIXEL/8 ,
(BYTE*) lockedRect.pBits + i* lockedRect.Pitch ,
ScreenWidth * BITSPERPIXEL/8);
它薩姆斯lockedRect.pBits或:在這條線
Unhandled exception at 0x58b6be20 (msvcr100d.dll) in SimpleSample.exe: 0xC0000005: Access violation reading location 0x00000000.
和程序中斷lockedRect.Pitch地址mem不是創建.... 你覺得呢? 請幫我解決這個問題。 謝謝。