积极答复者
directx 截屏 后 如何获取 BITMAPINFOHEADER 和RGB数据?

问题
-
LPDIRECT3D9 g_pD3D = NULL;
D3DDISPLAYMODE ddm;
D3DPRESENT_PARAMETERS d3dpp;
IDirect3DDevice9 * g_pd3dDevice;
IDirect3DSurface9 * pSurface;
ZeroMemory(&d3dpp,sizeof(D3DPRESENT_PARAMETERS));
ZeroMemory( &d3dpp, sizeof(d3dpp) );g_pD3D=Direct3DCreate9(D3D_SDK_VERSION);
g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&ddm);
d3dpp.Windowed=TRUE;
d3dpp.Flags=D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
d3dpp.BackBufferFormat=ddm.Format;
d3dpp.BackBufferHeight=ddm.Height;
d3dpp.BackBufferWidth=ddm.Width;
d3dpp.MultiSampleType=D3DMULTISAMPLE_NONE;
d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow=GetDesktopWindow();
d3dpp.PresentationInterval=D3DPRESENT_INTERVAL_DEFAULT;
d3dpp.FullScreen_RefreshRateInHz=D3DPRESENT_RATE_DEFAULT;HRESULT hr = g_pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,GetDesktopWindow(),D3DCREATE_SOFTWARE_VERTEXPROCESSING ,&d3dpp,&g_pd3dDevice);
hr = g_pd3dDevice->CreateOffscreenPlainSurface(ddm.Width, ddm.Height, D3DFMT_A8R8G8B8, /*D3DPOOL_SYSTEMMEM*/D3DPOOL_SCRATCH, &pSurface, NULL);
hr = g_pd3dDevice->GetFrontBufferData(0, pSurface);
LPD3DXBUFFER bufferedImage = NULL;
hr = D3DXSaveSurfaceToFileInMemory( &bufferedImage, D3DXIFF_DIB,pSurface,NULL,NULL);
//int ff=bufferedImage->GetBufferSize(); /*这个是图像的数据大小吗?*/
// LPVOID bufPoi= bufferedImage->GetBufferPointer(); /* 这个是图像RGB数据地址吗?*/该如何获取图像RGB数据呢?
txgx
答案
-
@txgx,
bufferedImage->GetBufferSize(); 应该是图像的Buffer的大小。
RGB value from bufferedImage我们可以看这个文档:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb172878(v=vs.85).aspx
首先我看你存的是D3DXIFF_DIB,那存储的应该就是这样的一个格式:
Windows DIB. Contains an array of bits combined with structures that specify width and height of the bitmapped image, color format of the device where the image was created, and resolution of the device used to create that image. 你找一下Buffer和Dib的格式存储的方式,然后去读取这个以DIB格式的Buffer,应该有资料告诉你DIB怎么存在Buffer里面的。
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 txgx 2015年11月28日 23:20
全部回复
-
@txgx,
bufferedImage->GetBufferSize(); 应该是图像的Buffer的大小。
RGB value from bufferedImage我们可以看这个文档:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb172878(v=vs.85).aspx
首先我看你存的是D3DXIFF_DIB,那存储的应该就是这样的一个格式:
Windows DIB. Contains an array of bits combined with structures that specify width and height of the bitmapped image, color format of the device where the image was created, and resolution of the device used to create that image. 你找一下Buffer和Dib的格式存储的方式,然后去读取这个以DIB格式的Buffer,应该有资料告诉你DIB怎么存在Buffer里面的。
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 txgx 2015年11月28日 23:20
-
这个是我绘图的方法:
void draw(HWND m_hWnd ,int sizedata,LPVOID data, D3DDISPLAYMODE ddm)
{
BITMAPINFOHEADER *bmif=new BITMAPINFOHEADER;
memset(bmif,0,sizeof(BITMAPINFOHEADER));
int len_header=sizeof(BITMAPINFOHEADER);bmif->biBitCount=32;
bmif->biHeight=ddm.Height;
bmif->biPlanes=1;
bmif->biSize=len_header;
bmif->biWidth=ddm.Width;
HDC hdc1 =NULL;
hdc1=GetDC(m_hWnd); /* 显示图片的窗体句柄 */HDRAWDIB hdd = DrawDibOpen();
BOOL rst =::DrawDibBegin (hdd,hdc1,bmif->biWidth,bmif->biHeight,bmif,bmif->biWidth,bmif->biHeight,DDF_SAME_DRAW| DDF_SAME_HDC);
DrawDibRealize(hdd,hdc1, FALSE);DrawDibDraw(hdd,hdc1,0, 0,bmif->biWidth,bmif->biHeight,bmif,((byte*)data),
0,0, bmif->biWidth,bmif->biHeight, DDF_SAME_DRAW|DDF_SAME_HDC);
DrawDibEnd(hdd);
DrawDibClose(hdd);
ReleaseDC(m_hWnd,hdc1);delete bmif;
}
txgx
- 已编辑 txgx 2015年11月26日 23:06