关于视频流pBuffer 转Bitmap问题 求指点
有一相机,
int CALLBACK SnapThreadCallback(BYTE *pBuffer, DI_DATA_TYPE Type, LPVOID lpContext),这个视频流的回调函数,其中type是RGB24的格式。
目标是: 想把每一帧图像 转为 Bitmap类型 .
怎么知道, 这byte数组是 整个BMP的文件数据? 还是不包括文件头和信息头的数据呢?
小弟刚刚接触, 求各位大神 多多指点。
求思路, 求代码。 3Q~~~
视频流 bitmap callback bmp
[解决办法]
看来 信息头 也要自己写了,上网搜。 可以先写到文件里,要是文件对了,再换成写到内存 pBmpData 中生成图像
[解决办法]
RGB24格式的数据直接调用SaveDIB2Bmp即可。
//构建BMP位图文件头
void ContructBhh(int nWidth,int nHeight,BITMAPFILEHEADER& bhh) //add 2010-9-04
{
int widthStep = (((nWidth * 24) + 31) & (~31)) / 8 ; //每行实际占用的大小(每行都被填充到一个4字节边界)
bhh.bfType = ((WORD) ('M' << 8)
[解决办法]
'B'); //'BM'
bhh.bfSize = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER) + widthStep * nHeight;
bhh.bfReserved1 = 0;
bhh.bfReserved2 = 0;
bhh.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER);
}
//构建BMP文件信息头
void ConstructBih(int nWidth,int nHeight,BITMAPINFOHEADER& bih)
{
int widthStep = (((nWidth * 24) + 31) & (~31)) / 8 ;
bih.biSize=40; // header size
bih.biWidth=nWidth;
bih.biHeight=nHeight;
bih.biPlanes=1;
bih.biBitCount=24; // RGB encoded, 24 bit
bih.biCompression=BI_RGB; // no compression 非压缩
bih.biSizeImage=widthStep*nHeight*3;
bih.biXPelsPerMeter=0;
bih.biYPelsPerMeter=0;
bih.biClrUsed=0;
bih.biClrImportant=0;
}
//iWidth:图像宽; iHeight:图像高;pBuffer:图像RGB数据;filePath:存储路径;fileName:保存文件名;
bool SaveDIB2Bmp(CString cstrSaveBmpPath, int iWidth, int iHeight, BYTE *pBuffer)
{
BITMAPINFOHEADER bih;
ConstructBih(iWidth,iHeight,bih);
BITMAPFILEHEADER bhh;
ContructBhh(iWidth,iHeight,bhh);
int widthStep = (((iWidth * 24) + 31) & (~31)) / 8 ; //每行实际占用的大小(每行都被填充到一个4字节边界)
int DIBSize = widthStep * iHeight ; //buffer的大小 (字节为单位)
CFile file;
try
{
if(file.Open(cstrSaveBmpPath,CFile::modeWrite
[解决办法]
CFile::modeCreate))
{//写入文件
file.Write((LPSTR)&bhh,sizeof(BITMAPFILEHEADER));
file.Write((LPSTR)&bih,sizeof(BITMAPINFOHEADER));
file.Write(pBuffer,DIBSize);
file.Close();
return true;
}
}
catch (...)
{
}
return false;
}
[解决办法]
GetLastError
看看什么 错