[DirectShow] Capture Picture Collection
"From the DirectShow example Stillcap"
DirectShow capturing images requires two interfaces: ISAMPLEGRABBERCB and Isamplegrabber. "CB" means Callback, as the name suggests, the ISAMPLEGRABBERCB interface provides callbacks for the Isamplegrabber interface, where the two methods of the ISAMPLEGRABBERCB interface are two callback functions. To achieve the snapshot, according to the following steps:
1. View plain Copy to clipboard print?//define a class that implements the ISAMPLEGRABBERCB interface BUFFERCB () . class csamplegrabbercb : public isamplegrabbercb { STDMETHODIMP BUFFERCB ( double dblSampleTime, BYTE * pBuffer, long lbuffersize ) { //Save the data in Pbuffer, which is a snapshot of the image } } //Create a CSAMPLEGRABBERCB instance csamplegrabbercb mcb; //Defines a class that implements the BUFFERCB () of the ISAMPLEGRABBERCB interface. Class Csamplegrabbercb:public ISAMPLEGRABBERCB {stdmethodimp BUFFERCB (double dblsampletime, BYTE * pbuffer, Long LBuff Ersize) {//Save the data in pbuffer, this data is the captured picture}//Create a CSAMPLEGRABBERCB instance CSAMPLEGRABBERCB MCB;
2. View plain Copy to clipboard print?//Create a Isamplegrabber instance ccomptr< isamplegrabber > ; m_pgrabber; m_pgrabber.cocreateinstance ( CLSID_SampleGrabber ); // Set Media type m_pgrabber->setmediatype (...); //Add Isamplegrabber to graph ccomqiptr< ibasefilter, &iid_ibasefilter > pgrabbase ( m_pGrabber ); m_pgraph->addfilter ( pgrabbase, l " Grabber " "; //Set callback function M_pgrabber->setcallback ( &mCB, 1 ); //Create a Isamplegrabber instance ccomptr< isamplegrabber > M_pgrabber; M_pgrabber.cocreateinstance (Clsid_samplegrabber); Set Media type M_pgrabber->setmediatype (...); Add Isamplegrabber to Graph ccomqiptr< ibasefilter, &iid_ibasefilter > Pgrabbase (m_pgrabber); M_pgraph->addfilter (Pgrabbase, L "grabber"); Set callback function M_pgrabber->setcallback (&MCB, 1);
When graph starts to run, graph will call BUFFERCB every time a frame of data is received, so you need to set a switch in the BUFFERCB, start the switch when snapping the picture, and then close the switch after saving the picture.