Memory Directx Backbuffer capturing

Memory Directx Backbuffer capturing,memory,graphics,directx,capture,directx-9,Memory,Graphics,Directx,Capture,Directx 9,i want to capture my Directx screen from backbuffer to memory address by using "memcpy" function. so i wrote this codes: 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,

i want to capture my Directx screen from backbuffer to memory address by using "memcpy" function. so i wrote this codes:

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();

but when program run i got this error:

Unhandled exception at 0x58b6be20 (msvcr100d.dll) in SimpleSample.exe: 0xC0000005: Access violation reading location 0x00000000.

and program break on this line :

 memcpy( (BYTE*) pBits + i * ScreenWidth * BITSPERPIXEL / 8 , 
        (BYTE*) lockedRect.pBits + i* lockedRect.Pitch , 
        ScreenWidth * BITSPERPIXEL / 8);

it sames lockedRect.pBits or lockedRect.Pitch address mem was not create .... what u think? please help me to solve this problem. thank you.


#1

Did you use D3DMEM_POOL? Are you sure that backbuffer format X8A8R8B8?


#2

Trying to find the answer for the same. From some sources I am able to figure out that there back buffers are application specific. i.e. they write data on the back buffer bound to them.

I am trying to figure out where the first parameter in the GetBackBuffer() plays role? It's iSwapChain. MSDN help is little.


#3

Did you use D3DMEM_POOL? Are you sure that backbuffer format X8A8R8B8?


#4

Trying to find the answer for the same. From some sources I am able to figure out that there back buffers are application specific. i.e. they write data on the back buffer bound to them.

I am trying to figure out where the first parameter in the GetBackBuffer() plays role? It's iSwapChain. MSDN help is little.