资源描述:
《dshow中实现抓图的几种方法》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、DShow中实现抓图的几种方法1.加入SampleGrabberFilter当我们加入SampleGrabberFilter的时候,我们可以直接调用其接口(interface)ISampleGrabber。该接口可以获取经过该Filter的单独的MediaSamples。详情请参见DXSDK。1.1派生出自己的SampleGrabber从ISampleGrabberCB中派生出自己的类,然后实现其虚函数,详情请参见SDK中的示例程序(DXSDKROOTSamplesC++DirectShow
2、EditingGrabBitmaps)。1.2直接调用SampleGrabberFilter的接口如果我们在播放的过程中动态的加入Filter的话,操作和效率都不乐观。所以我采用下面的方法:该方法传递的是时间,不是在播放的时候动态加入Filter然后截图,而是另外打开源文件进行操作。A)。申明以下接口:A)。申明以下接口:#001IGraphBuilder*pGraph=NULL;//forgraphbuilder#002IMediaControl*pControl=NULL;//mediac
3、ontrol#003IMediaSeeking*pSeeking=NULL;//mediaseeking#004IMediaEventEx*pEvent=NULL;//mediaenvent#005IBaseFilter*pNullFilter=NULL;//forholdingtheSamplegrabberFilterB)。初始化接口:#001JIF(CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC,#002IID_IGraphBuil
4、der,(void**)&pGraph));#003#004JIF(CoCreateInstance(CLSID_NullRenderer,NULL,CLSCTX_INPROC,#005IID_IBaseFilter,(void**)&pNullFilter));#006JIF(pGraph->QueryInterface(IID_IMediaControl,(void**)&pControl));#007JIF(pGraph->QueryInterface(IID_IMediaSeeking,(
5、void**)&pSeeking));#008JIF(pGraph->QueryInterface(IID_IMediaEvent,(void**)&pEvent));C)。创建SampleGrabber#001//CreatetheSampleGrabber.#002IBaseFilter*pGrabberF=NULL;#003JIF(CoCreateInstance(CLSID_SampleGrabber,NULL,CLSCTX_INPROC_SERVER,#004IID_IBaseFilte
6、r,(void**)&pGrabberF));#005#006JIF(pGraph->AddFilter(pGrabberF,L"SampleGrabber"));#007JIF(pGraph->AddFilter(pNullFilter,L"NullRenderFilter"));#008#009ISampleGrabber*pGrabber;#010JIF(pGrabberF->QueryInterface(IID_ISampleGrabber,(void**)&pGrabber));设置Sa
7、mpleGrabber的媒体格式:调用SetMediaType,该函数接受一个AM_MEDIA_TYPE的结构,主要是设置该结构中的majortype,和subtype域。D)。添加SourceFilter:#001IBaseFilter*pSrc;#002JIF(pGraph->AddSourceFilter(T2W(m_szFile),L"Source",&pSrc));E)。连接Grabber和NullRender两个Filter:#001IPin*pOutPin;#002hr=GetPin
8、(pGrabberF,PINDIR_OUTPUT,&pOutPin);#003#004IPin*pInPin;#005hr=GetPin(pNullFilter,PINDIR_INPUT,&pInPin);#006#007pGraph->Connect(pOutPin,pInPin);F)。取得当前所连接媒体的类型#001AM_MEDIA_TYPEmt;#002hr=pGrabber->GetConnectedMediaType(&mt);#003//Examinetheforma