[摘要]CFile::typeBinary); #032 bitmapFile.Write(&hdr, sizeof(BITMAPFILEHEADER)); #033 ...
CFile::typeBinary);
#032 bitmapFile.Write(&hdr, sizeof(BITMAPFILEHEADER));
#033 bitmapFile.Write(buffer, bitmapSize);
#034 bitmapFile.Close();
#035 pass = true;
#036 }
#037 delete [] buffer; //数据用过之后记得要释放空间
#038 return true;
#039 }
#040 }
#041
#042 return false;
#043 }
IMediaDet接口
IMediaDet接口可以取得媒体文件的信息。SDK里面的示例代码(没有写入文件):
#001 long size;
#002 //取得图像帧的大小,给GetBitmapBits的第三个参数传递0 or NULL
#003 hr = pDet->GetBitmapBits(0, &size, 0, width, height);
#004 if(SUCCEEDED(hr))
#005 {
#006 char *pBuffer = new char[size];
#007 if(!pBuffer)
#008 {
#009 return E_OUTOFMEMORY;
#010 }
#011
#012 try
#013 {
#014 hr = pDet->GetbitmapsBits(0, 0, pBuffer, width, height);
#015 }
#016 catch(...)
#017 {
#018 delete [] pBuffer;
#019 throw;
#020 }
#021
#022 if(SUCCEEDED(hr))
#023 {
#024 BITMAPINFOHEADER *bmih = (BITMAPINFOHEADER*)pBuffer;
#025 HDC hdcDest = GetDC(0);
#026
#027 //Find the address of the start of the image data
#028 void *pData = pBuffer + sizeof(BITMAPINFOHEADER);
#029
#030 //Note: In general a BITMAPINFOHEADER can include extra color
#031 //information at the end, so calculating the offset to the image
#032 //data i snot generally correct. However, the IMediaDet interface
#033 //always returns an RGB-24 image with no extra color information
#034
#035 BITMAPINFO bmi;
#036 ZeroMemory(&bmi, sizeof(BITMAPINFO));
#037 CopyMemory(&(bmi.bmiHeader), bmih, sizeof(BITMAPINFOHEADER));
#038 HBITMAP hBitmap = CreateDIBitmap(hdcDect, bmih, CBM_INIT,
#039 pData, &bmi, DIB_RGB_COLORS);
#040 }
#041
#042 delete [] pBuffer;
#043 }
该方法并没有写入bitmap,具体的写入过程可以参加上面的几种方法。
关键词:DShow中完成抓图的几种办法