本文章主要解决问题为:视频数据经过解码后,生成RGB24格式的RGB数据即没有Bitmap头的BMP数据。所用方案为DirectDraw和GDI+的实现方法。代码如下:
int CVideoDraw::DrawImage( LPBYTE pImageBuffer, int nImageWidth, int nImageHeight )
{
HRESULT hr;
DDSURFACEDESC2 ddsd2;
ZeroMemory(&ddsd2,sizeof(ddsd2));
ddsd2.dwSize = sizeof(ddsd2);
if(NULL == m_lpddsrealback)
{
ddsd2.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH ;/*| DDSD_PIXELFORMAT*/;
ddsd2.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;
ddsd2.dwHeight = nImageHeight;
ddsd2.dwWidth = nImageWidth;
if (FAILED(hr = m_lpdd7->CreateSurface(&ddsd2,&m_lpddsrealback,NULL)))
{
DXGetErrorString(hr);
return -1;
}
m_pcBitData = Bitmap::FromDirectDrawSurface7(m_lpddsrealback);
}
/*if(FAILED(hr = m_lpddsrealback->Restore()))
{
DXGetErrorString(hr);
return -1;
}*/
Rect rc( 0, 0, nImageWidth, nImageHeight );
BitmapData bitmapData;
bitmapData.Width = nImageWidth;
bitmapData.Height = nImageHeight;
bitmapData.Stride = 3 * nImageWidth;
bitmapData.PixelFormat = PixelFormat24bppRGB;
bitmapData.Scan0 = (void*)pImageBuffer;
bitmapData.Reserved = NULL;
m_pcBitData->LockBits( &rc, ImageLockModeWrite | ImageLockModeUserInputBuf, PixelFormat24bppRGB, &bitmapData );
m_pcBitData->UnlockBits( &bitmapData );
DDBLTFX ddbltfx;//声明一个DDBLTFX变量
memset(&ddbltfx, 0, sizeof(ddbltfx));//同样,将内存清0
ddbltfx.dwSize=sizeof(ddbltfx);//同样,填入该结构的字节数
RECT client;
GetWindowRect(m_hVideoWnd,&client);
if(FAILED(hr = m_lpddsprimary->Blt(&client, m_lpddsrealback, NULL, DDBLT_DDFX | DDBLT_WAIT, &ddbltfx)))
{
DXGetErrorString(hr);
return -1;
}
return 0;
}