[DirectShow] capture picture to paste _graph

Source: Internet
Author: User
[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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.