1.新建一个对话框取名摄像头
注意路径格式,自己修改。
2.在其中加入一个picture control控件(显示摄像),一个comb控件(存储本机有的摄像头),一个button按钮(拍照)。
给picture control控件设置控制变量命名为my_device comb控件设置控制变量命名为mylist。
3.准备好VMR_Capture.h文件和VMR_Capture.cpp文件,分别加入到头文件和源文件中
4.打开摄像头Dlg.h头文件在protected中加入变量
CVMR_Capture m_VMRCap;
CString m_yuvFileName;
CFile m_pFile;
int m_imageWidth;
int m_imageHeight;
各种头文件宏定义自己补充
#include "stdafx.h"
#include "摄像头.h"
#include "摄像头Dlg.h"
#include "afxdialogex.h"
#include "VMR_Capture.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#define CAMERA_WIDTH 640 //352
#define CAMERA_HEIGHT 480
5.在 摄像头Dlg.cpp 中找到BOOL C摄像头Dlg::OnInitDialog()函数添加如下代码
int m_imageWidth = CAMERA_WIDTH;
int m_imageHeight= CAMERA_HEIGHT;
this->m_VMRCap.EnumDevices(this->mylist);
this->mylist.SetCurSel(0);
int id = this->mylist.GetCurSel();
HRESULT hr = m_VMRCap.Init(id,my_device.GetSafeHwnd(),m_imageWidth,m_imageHeight);
if (FAILED(hr))
AfxMessageBox(_T("无法创建滤波器链表!"));
6.双击拍照按钮,补充代码如下
CString sfile="C:\\Users\\Administrator\\Desktop\\sgad.jpg";
m_VMRCap.ImageCapture(sfile);
注意路径格式,自己修改。
7.给comb添加消息CBN_SELCHANGE
编辑代码如下
m_VMRCap.CloseInterfaces();
ong m_imageWidth = CAMERA_WIDTH;
long m_imageHeight= CAMERA_HEIGHT;
HWND hwnd = this->my_device.GetSafeHwnd();
int id = this->mylist.GetCurSel();
HRESULT hr = m_VMRCap.Init(id,hwnd,m_imageWidth,m_imageHeight);
编译运行。