上传者: nndcs
|
上传时间: 2022-11-13 18:54:32
|
文件大小: 1.94MB
|
文件类型: ZIP
可用来在VB,VC中驱动摄像头,进行静帧捕捉的DLL动态链接库(必须要有摄像头生成StillCap0000.bmp):将MyDll文件解压后把MyDll.dll与MyDll.lib一起拷入工程DEBUG目录中(为保险起见DEBUG的外层目录也拷贝一份吧),另有一个VC++6的测试工程test_Dll,已经考入相应DLL和LIB文件,可直接编译运行,VB只拷贝MyDll.dll与MyDll.lib
VB2008 调用方法,在公共模块中声名:
Public Declare Function CreateWnd Lib "MyDll" () As Double
Public Declare Function ClearGraphs Lib "MyDll" () As Double
Public Declare Function OnpStillCapture Lib "MyDll" (ByVal hwnd As Long) As Double
Public Declare Function InitStillGraph Lib "MyDll" (ByVal hwnd As Long) As Double
Public Declare Function CloseWnd Lib "MyDll" () As Double
在窗体上放置2个PictureBox控件,名字为:pic1,pic2
放置三个按键:名字为Btn1,Btn2,Btn3
Btn1为打开视频,调用代码:
Private Sub Btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn1.Click
InitStillGraph(pic1.Handle) '打开摄像头预览视频
end sub
Btn2为截取视频保存为BMP,文件保存在应用程序路径下,调用代码:
Private Sub Btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn2.Click
OnpStillCapture(pic2.Handle) '截取预览视频一帧图像
end sub
Btn3为截取视频保存为清除内存,调用代码:
Private Sub Btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn3.Click
ClearGraphs() '退出前,完成内存清扫工
end sub
VC调用方法:
在对话框上放置两个图像框,类型为位图,三个按键B1,B2,B3
定义全局函数引用:
typedef HWND(* CreateWnd)(void);//
typedef HRESULT(* InitStillGraph)(HWND hwnd);
typedef void (* OnpStillCapture)(HWND hwnd);
typedef int (* ClearGraphs)();
HINSTANCE glibsample; //如果定义成HANDLE类型,则出错
CreateWnd createwnd;
InitStillGraph initStillGraph;//定义引用函数
OnpStillCapture onpStillCapture;//定义引用函数
ClearGraphs clearGraphs;//定义引用函数
用类向导为两个位图框建立控件(类型为Contorl)变量,m_p1,m_2
:
在窗口OnInitDialog()函数中调整图像框大小:
// TODO: Add your specialized code here and/or call the base class
m_p1.MoveWindow(0,0,200,200,true);
m_p2.MoveWindow(210,0,200,200,true);
glibsample=LoadLibrary("MyDll.dll"); //加载dll
在B1消息函数中:
void 你的类::OnB1()
{
initStillGraph=(InitStillGraph)GetProcAddress(glibsample,"InitStillGraph");
(*initStillGraph)(m_p1.m_hWnd);//预览图像
}
在B2消息函数中:
void 你的类::OnB2()
{
// TODO: Add your control notification handler code here
onpStillCapture=(OnpStillCapture)GetProcAddress(glibsample,"OnpStillCapture");
(*onpStillCapture)(m_p2.m_hWnd);//采集静帧图像文件存在应用程序目录
}
在B2消息函数中:
void 你的类::OnB3()
{
// TODO: Add your control notification handler code here
clearGraphs=(ClearGraphs)GetProcAddress(glibsample,"ClearGraphs");
(*ClearGraphs)(hwnd);//清扫工作
}
如果调用:CreateWnd()可产生一个预览视频窗口
代码为:HWND handle1=CreateWnd()
InitStillGraph(handle1)
最后用ClearGraphs() 和CloseWnd(handle1)释放窗口
以上代码在VB2008、vC++6 windows2003R2 测试通过