• Advertisement
Sign in to follow this  

Capturing desktop image using DirectX is feasible or not?

This topic is 4433 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I have made an application(server) that captures the image of its display screen using GDI APIs. All is fine but capturing of the image is using BitBlt Source copy that is slow. someone suggests me to test capturing of desktop image using DirectX frontbuffer bcz it provides direct access to video card memory. I m not used to with directX so i dont know how to do it and whether it will be more efficient then tradiational BitBlt or not. Plz help me regarding to capturing and performance gain that i can have using it. Thanx

Share this post


Link to post
Share on other sites
Advertisement

void Graphics::takeScreenShot(LPCTSTR pDestFile)
{
D3DDISPLAYMODE displayMode;

LPDIRECT3DSURFACE9 pd3dsFront = NULL;

// Get the display mode
m_pd3dDevice->GetDisplayMode(0, &displayMode);

// Create a surface to hold the front buffer
m_pd3dDevice->CreateOffscreenPlainSurface(displayMode.Width, displayMode.Height,
D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &pd3dsFront, NULL);

// Get the front buffer and save it to a file
if( SUCCEEDED( m_pd3dDevice->GetFrontBufferData(0, pd3dsFront) ) )
D3DXSaveSurfaceToFile(pDestFile, D3DXIFF_BMP, pd3dsFront, NULL, NULL);

// Release the surface
if( pd3dsFront ) pd3dsFront->Release();
}

void Graphics::takeScreenShotEx(LPCTSTR pDestFile)
{
LPDIRECT3DSURFACE9 pd3dSurface;
m_pd3dDevice->GetRenderTarget(0, &pd3dSurface);

D3DXSaveSurfaceToFile(pDestFile, D3DXIFF_BMP, pd3dSurface, NULL, NULL);

pd3dSurface->Release();
}

LPDIRECT3DTEXTURE9 Graphics::createTextureFromRT()
{
LPDIRECT3DSURFACE9 surface = NULL;
D3DSURFACE_DESC surfDesc;
LPDIRECT3DTEXTURE9 texture;
LPDIRECT3DSURFACE9 texSurface;

// get the back surface and its description
m_pd3dDevice->GetRenderTarget(0, &surface);
surface->GetDesc(&surfDesc);
surface->Release(); surface=NULL;

// create a surface to hold the front buffer
m_pd3dDevice->CreateOffscreenPlainSurface(surfDesc.Width, surfDesc.Height,
D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surface, NULL);

// get the front surface
m_pd3dDevice->GetFrontBufferData(0, surface);

// create a texture the same as the front surface
m_pd3dDevice->CreateTexture(surfDesc.Width, surfDesc.Height, 0, D3DUSAGE_AUTOGENMIPMAP|D3DUSAGE_DYNAMIC, surfDesc.Format, D3DPOOL_DEFAULT, &texture, NULL);

// get the textures surface
texture->GetSurfaceLevel(0, &texSurface);

// copy the front surface to the textures surface
D3DXLoadSurfaceFromSurface(texSurface, NULL, NULL, surface, NULL, NULL, D3DX_DEFAULT, 0);

// release both surfaces
texSurface->Release();
surface->Release();

// and your left with a a d3d texture containing the front surface
return texture;
}


Share this post


Link to post
Share on other sites
Dear
I know how to capture it using directX but i ask
is it feasible to use directX than BitBlt.
Can i get performance gain with less CPU usage.
Bcz i have to capture images of each update in the
display.

Thanx for ur reply.

Share this post


Link to post
Share on other sites
Did you try it? Seems to me it'd be much quicker to use eFoDay's code and test for yourself, rather than waiting for someone else to do it for you...

Share this post


Link to post
Share on other sites
Its fine dear,
but the code u have given me is saving the bitmap in a file.
I need in memory(system memory) bitmap like HBITMAP.
I dont want to save it into file then what should i do?
Also If i want to capture a rectangular region not the whole
desktop then how is it possible?

Thanx for ur response

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement