Creating a HBITMAP from a LPD3DXBUFFER
First of all is this possible
Below is my current code with the annotated space where this transformation is required.
HBITMAP MyClass::ScreenGrab()
{
//RenderTargetSurface.
IDirect3DSurface9* pRenderTargetSurface = NULL;
//DestinationTargetSurface
IDirect3DSurface9* pDestinationTargetSurface = NULL;
//DisplayMode
D3DDISPLAYMODE d3dDipMode;
//HBITMAP that will be the return of the method
HBITMAP hbm;
if (m_pd3dDevice == NULL)
return NULL;
//Get the client rectangle
RECT rc;
GetClientRect(myhWnd, &rc);
ClientToScreen(myhWnd, LPPOINT(&rc.left));
ClientToScreen(myhWnd, LPPOINT(&rc.right));
//GetRenderTargetSurface.
if(FAILED(m_pd3dDevice->GetRenderTarget(0, &pRenderTargetSurface)))
return NULL;
//Display Mode (d3dDipMode)
if(FAILED(m_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3dDipMode)))
return NULL;
//GetDestinationTargetSurface
if(FAILED(m_pd3dDevice->CreateOffscreenPlainSurface((rc.right - rc.left),
(rc.bottom - rc.top),
d3dDipMode.Format,
D3DPOOL_SYSTEMMEM,
&pDestinationTargetSurface,
NULL)))
return NULL;
//copy RenderTargetSurface -> DestTarget
if(FAILED(m_pd3dDevice->GetRenderTargetData(pRenderTargetSurface, pDestinationTargetSurface)))
return NULL;
LPD3DXBUFFER bufferedImage = NULL;
//Save the DestinationTargetSurface into memory (as a bitmap)
if(FAILED(D3DXSaveSurfaceToFileInMemory(&bufferedImage,
D3DXIFF_BMP,
pDestinationTargetSurface,
NULL,
NULL)))
return NULL;
//TRANSFORMATION REQUIRED HERE!!!!
//I WANT TO TRANSFORM bufferedImage INTO A HBITMAP SO THAT THE METHOD RETURNS
//THAT HBITMAP TO FULFIL MY CONTRACT.
//Release Resources
pRenderTargetSurface->Release();
pDestinationTargetSurface->Release();
//Return HBITMAT
return hbm;
}
.
Thanks for your help in advance,
Alex.
Creating a HBITMAP from a LPD3DXBUFFER
bignack
PrasannaGPKBE
I have just looked at CreateDIBitmap() in the SDK documentation and googled for some decent examples. This looks horrendous! If you could point me in the right direction with a little example I would be forever in your debt.
Thanks,
Alex.
BBA
Alex.
kangalert
steve brsk
The OP asked the same question over at GDNet and it seems to have gather more replies. Anyone else with a similar problem may wish to check out the discussion here.
Cheers,
Jack