上一篇讲了怎么采集摄像头图像并预览,本篇主要讲预览的同时怎么拍照。
拍照就需要抓取图像,这里要用到一个不太一样的Filter,叫SampleGrabber Filter,通过这个Filter可以获取到ISampleGrabber接口,通过这个接口就可以设置抓取什么样的视频。对于这个接口获取采集到的每一帧的信息,我们可以对其进行处理,可以拿来显示,也可以用来生成图片。下面来一步一步做做看。
首先,我新定义了一个结构,用来存采集设备支持的所有分辨率,ASCamResolutionInfoArray m_arrCamResolutionArr; 它的结构定义如下:
struct CamResolutionInfo
{
int nWidth; //分辨率宽
int nHeight; //分辨率高
int nResolutionIndex; //分辨率序号
CamResolutionInfo()
{
nWidth = 640;
nHeight = 480;
nResolutionIndex = -1;
};
CamResolutionInfo(const CamResolutionInfo &other)
{
*this = other;
};
CamResolutionInfo& operator = (const CamResolutionInfo& other)
{
nWidth = other.nWidth;
nHeight = other.nHeight;
nResolutionIndex = other.nResolutionIndex;
return *this;
};
};
typedef CArray <CamResolutionInfo, CamResolutionInfo&> ASCamResolutionInfoArray;
然后获取采集设备支持的所有分辨率,代码如下:
void CGetDeviceInfoDlg::GetVideoResolution()
{
if (m_pCapture)
{
m_arrCamResolutionArr.RemoveAll();
m_cbxResolutionCtrl.ResetContent();
IAMStreamConfig *pConfig = NULL;
//&MEDIATYPE_Video,如果包括其他媒体类型,第二个参数设置为0
HRESULT hr = m_pCapture->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
m_pVideoFilter, IID_IAMStreamConfig, (void **)&pConfig);
int iCount = 0, iSize = 0;
hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize);
// Check the size to make sure we pass in the correct structure.
if (iSize == size