DirectShow图片的抓取
2010-08-11 14:31
第1种方法是使用IBasicVideo::GetCurrentImage: bool SnapshotBitmap(IBaseicVideo *pBasicVideo,const char *outFile) { if(pBasicVideo) { long bitmapSize=0; //首先获得图像大小 if(SUCCEEDED(pBasicVideo->GetCurrentImage(&bitmapSize,0))) { bool pass=false; //分配图像帧内存 unsigned char *buffer=new unsigned char[bitmapSize]; //获取图像帧数据 if(SUCCEEDED(pBasicVideo->GetCurrentImage(&bitmapSize,(long*)buffer))) { BITMAPFILEHEADER hdr; LPBITMAPINFOHEADER lpbi; lpbi=(LPBITMAPINFOHEADER)buffer; int nColors=1<<lpbi->biBitCount; if(nColors>256) nColors=0; hdr.bfType=((WORD)('M'<<8)|'B'); hdr.bfSize=bitmapSize+sizeof(hdr); hdr.bfReserved1=0; hdr.bfReserved2=0; hdr.bfOffBits=(DWORD)(sizeof(BITMAPFILEHEADER)+lpbi->biSize+nColors*sizeof(RGBQUAD)); CFile bitmapFile(outFile,CFile::modeReadWrite|CFile::modeCreate|CFile::typeBinary); //写入位图文件头 bitmapFile.Write(&hdr,sizeof(BITMAPFILEHEADER)); //写入图像帧数据 bitmapFile.Write(buffer,bitmapSize); bitmapFile.Close(); pass=true; } delete []buffer; return pass; } } return false; } 第2种方法比较复杂,使用Sample Grabber Filter. |