一个驱动webcam的类,利用通用的摄像头驱动程序avicap32.dll

avicap32.dll动态链接库详解与应用实战 Windows操作系统自诞生以来,始终致力于为开发者提供一套强大而灵活的多媒体支持体系。在图形、音频和视频处理领域,Windows通过一系列层次分明、职责清晰的API架构实现了对底层硬件资源的抽象化管理,使得应用程序能够在不同设备与驱动之间实现无缝兼容。其中,早期以Video for Windows(VfW)为代表的多媒体框架奠定了视频捕获技术的基础,而后续演进至DirectShow、Media Foundation等现代架构,则进一步提升了系统在高分辨率、低延迟和多格式支持方面的表现能力。 阅读详情

Imports System.Runtime.InteropServices

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer. 
    'Do not modify it using the code editor.
    Friend WithEvents picCapture As System.Windows.Forms.PictureBox
    Friend WithEvents lstDevices As System.Windows.Forms.ListBox
    Friend WithEvents lblDevice As System.Windows.Forms.Label
    Friend WithEvents btnStart As System.Windows.Forms.Button
    Friend WithEvents btnSave As System.Windows.Forms.Button
    Friend WithEvents btnStop As System.Windows.Forms.Button
    Friend WithEvents sfdImage As System.Windows.Forms.SaveFileDialog
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.picCapture = New System.Windows.Forms.PictureBox()
        Me.lstDevices = New System.Windows.Forms.ListBox()
        Me.lblDevice = New System.Windows.Forms.Label()
        Me.btnStart = New System.Windows.Forms.Button()
        Me.btnSave = New System.Windows.Forms.Button()
        Me.btnStop = New System.Windows.Forms.Button()
        Me.sfdImage = New System.Windows.Forms.SaveFileDialog()
        Me.SuspendLayout()
        '
        'picCapture
        '
        Me.picCapture.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.picCapture.Location = New System.Drawing.Point(208, 24)
        Me.picCapture.Name = "picCapture"
        Me.picCapture.Size = New System.Drawing.Size(256, 272)
        Me.picCapture.TabIndex = 0
        Me.picCapture.TabStop = False
        '
        'lstDevices
        '
        Me.lstDevices.Location = New System.Drawing.Point(8, 55)
        Me.lstDevices.Name = "lstDevices"
        Me.lstDevices.Size = New System.Drawing.Size(184, 238)
        Me.lstDevices.TabIndex = 1
        '
        'lblDevice
        '
        Me.lblDevice.Location = New System.Drawing.Point(8, 32)
        Me.lblDevice.Name = "lblDevice"
        Me.lblDevice.Size = New System.Drawing.Size(184, 16)
        Me.lblDevice.TabIndex = 2
        Me.lblDevice.Text = "Available Devices"
        Me.lblDevice.TextAlign = System.Drawing.ContentAlignment.TopCenter
        '
        'btnStart
        '
        Me.btnStart.Location = New System.Drawing.Point(20, 320)
        Me.btnStart.Name = "btnStart"
        Me.btnStart.Size = New System.Drawing.Size(112, 32)
        Me.btnStart.TabIndex = 3
        Me.btnStart.Text = "Start Preview"
        '
        'btnSave
        '
        Me.btnSave.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right)
        Me.btnSave.Location = New System.Drawing.Point(348, 320)
        Me.btnSave.Name = "btnSave"
        Me.btnSave.Size = New System.Drawing.Size(112, 32)
        Me.btnSave.TabIndex = 4
        Me.btnSave.Text = "Save Image"
        '
        'btnStop
        '
        Me.btnStop.Location = New System.Drawing.Point(184, 320)
        Me.btnStop.Name = "btnStop"
        Me.btnStop.Size = New System.Drawing.Size(112, 32)
        Me.btnStop.TabIndex = 5
        Me.btnStop.Text = "Stop Preview"
        '
        'sfdImage
        '
        Me.sfdImage.FileName = "Webcam1"
        Me.sfdImage.Filter = "Bitmap|*.bmp"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(480, 382)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnStop, Me.btnSave, Me.btnStart, Me.lblDevice, Me.lstDevices, Me.picCapture})
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Video Capture"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Const WM_CAP As Short = &H400S

    Const WM_CAP_DRIVER_CONNECT As Integer = WM_CAP + 10
    Const WM_CAP_DRIVER_DISCONNECT As Integer = WM_CAP + 11
    Const WM_CAP_EDIT_COPY As Integer = WM_CAP + 30

    Const WM_CAP_SET_PREVIEW As Integer = WM_CAP + 50
    Const WM_CAP_SET_PREVIEWRATE As Integer = WM_CAP + 52
    Const WM_CAP_SET_SCALE As Integer = WM_CAP + 53
    Const WS_CHILD As Integer = &H40000000
    Const WS_VISIBLE As Integer = &H10000000
    Const SWP_NOMOVE As Short = &H2S
    Const SWP_NOSIZE As Short = 1
    Const SWP_NOZORDER As Short = &H4S
    Const HWND_BOTTOM As Short = 1

    Dim iDevice As Integer = 0 ' Current device ID
    Dim hHwnd As Integer ' Handle to preview window

    Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
        (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, _
        <MarshalAs(UnmanagedType.AsAny)> ByVal lParam As Object) As Integer

    Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Integer, _
        ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, _
        ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer

    Declare Function DestroyWindow Lib "user32" (ByVal hndw As Integer) As Boolean

    Declare Function capCreateCaptureWindowA Lib "avicap32.dll" _
        (ByVal lpszWindowName As String, ByVal dwStyle As Integer, _
        ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, _
        ByVal nHeight As Short, ByVal hWndParent As Integer, _
        ByVal nID As Integer) As Integer

    Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal wDriver As Short, _
        ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, _
        ByVal cbVer As Integer) As Boolean

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadDeviceList()
        If lstDevices.Items.Count > 0 Then
            btnStart.Enabled = True
            lstDevices.SelectedIndex = 0
            btnStart.Enabled = True
        Else
            lstDevices.Items.Add("No Capture Device")
            btnStart.Enabled = False
        End If

        btnStop.Enabled = False
        btnSave.Enabled = False
        picCapture.SizeMode = PictureBoxSizeMode.StretchImage
    End Sub

    Private Sub LoadDeviceList()
        Dim strName As String = Space(100)
        Dim strVer As String = Space(100)
        Dim bReturn As Boolean
        Dim x As Integer = 0

        '
        ' Load name of all avialable devices into the lstDevices
        '

        Do
            '
            '   Get Driver name and version
            '
            bReturn = capGetDriverDescriptionA(x, strName, 100, strVer, 100)

            '
            ' If there was a device add device name to the list
            '
            If bReturn Then lstDevices.Items.Add(strName.Trim)
            x += 1
        Loop Until bReturn = False
    End Sub

    Private Sub OpenPreviewWindow()
        Dim iHeight As Integer = picCapture.Height
        Dim iWidth As Integer = picCapture.Width

        '
        ' Open Preview window in picturebox
        '
        hHwnd = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, 640, _
            480, picCapture.Handle.ToInt32, 0)

        '
        ' Connect to device
        '
        If SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) Then
            '
            'Set the preview scale
            '
            SendMessage(hHwnd, WM_CAP_SET_SCALE, True, 0)

            '
            'Set the preview rate in milliseconds
            '
            SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0)

            '
            'Start previewing the image from the camera
            '
            SendMessage(hHwnd, WM_CAP_SET_PREVIEW, True, 0)

            '
            ' Resize window to fit in picturebox
            '
            SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, picCapture.Width, picCapture.Height, _
                    SWP_NOMOVE Or SWP_NOZORDER)

            btnSave.Enabled = True
            btnStop.Enabled = True
            btnStart.Enabled = False
        Else
            '
            ' Error connecting to device close window
            '
            DestroyWindow(hHwnd)

            btnSave.Enabled = False
        End If
    End Sub

    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        iDevice = lstDevices.SelectedIndex
        OpenPreviewWindow()
    End Sub

    Private Sub ClosePreviewWindow()
        '
        ' Disconnect from device
        '
        SendMessage(hHwnd, WM_CAP_DRIVER_DISCONNECT, iDevice, 0)

        '
        ' close window
        '

        DestroyWindow(hHwnd)
    End Sub

    Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
        ClosePreviewWindow()
        btnSave.Enabled = False
        btnStart.Enabled = True
        btnStop.Enabled = False
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim data As IDataObject
        Dim bmap As Image

        '
        ' Copy image to clipboard
        '
        SendMessage(hHwnd, WM_CAP_EDIT_COPY, 0, 0)

        '
        ' Get image from clipboard and convert it to a bitmap
        '
        data = Clipboard.GetDataObject()
        If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
            bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Image)
            picCapture.Image = bmap
            ClosePreviewWindow()
            btnSave.Enabled = False
            btnStop.Enabled = False
            btnStart.Enabled = True

            If sfdImage.ShowDialog = DialogResult.OK Then
                bmap.Save(sfdImage.FileName, Imaging.ImageFormat.Bmp)
            End If

        End If
    End Sub

    Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        If btnStop.Enabled Then
            ClosePreviewWindow()
        End If
    End Sub
End Class


 
ezVidCap.ocx原理与Win10兼容性解决方案 ActiveX控件是Windows平台早期实现组件化开发的核心技术,其本质是基于COM模型的二进制可重用模块。ezVidCap.ocx作为典型代表,封装了Video for Windows(VFW)API,通过同步阻塞式调用实现视频捕获,体现了VB6时代‘低抽象、高可控’的工程哲学。其技术价值在于极简集成与硬件贴近性,适用于工控、医疗等对启动速度和资源占用敏感的嵌入式场景。然而在现代Windows中,因VFW API废弃、WoW64兼容层移除及UVC驱动架构替代,导致注册失败(0x80040154)、黑屏、 阅读详情

相关推荐

C#操作摄像头dll

用于开发调用摄像头的dll库,希望对初学者有帮助,自己也是在学习中找到的,一起学一起进步。

一个驱动webcam的类,利用通用的摄像头驱动程序avicap32.dll [vb.net]

---------------------------------------------------------Code By Ken Tucker--------------------------------------------------------------Imports System.Runtime.InteropServicesPublic Class Form1   

笔记本 1334

vb.net下的USB摄像头的程序

vb.net下的USB摄像头的程序 不是很好用,但能用。

(三)调用usb摄像头常用的5种方法:Aforge、WPFMediaKit、WinCap、avicap32.dll和DirectShow

一、简介        我们往往用Aforge,WPFMediaKit和WinCap这三种方法,来打开USB摄像头或网络摄像机等等,这三者方法是目前CSDM或GitHub上的的主流方法。而且,我们可以在GitHub找到源码。 该网页分析了它们的区别: https://blog.csdn.net/bornonew/article/details/53302416 1.1、Aforge(WPF...

xpj8888的博客 5424

vb USB摄像头控件

vb6 调用 ezVidCap.ocx 控件显示usb摄像头,并截图,截图转换为jpg,控件需要先注册才能用

基于VB6.0 摄像头监视系统

Private Sub MDIForm_Load() Me.Left = GetSetting(App.Title, "Settings", "MainLeft", 1000) '设置窗体左边坐标 Me.Top = GetSetting(App.Title, "Settings", "MainTop", 1000) '设置窗体顶端坐标 Me.Width = GetSetting(App.Title, "Settings", "MainWidth", 6500) '设置窗体宽度 Me.Height = GetSetting(App.Title, "Settings", "MainHeight", 6500) '设置窗体高度 CreateFolder App.Path & "\TEMP" '调过函数创建临时文件夹 EnableMenu '调用过程设置各菜单的可用状态 sngTime = 0 '设置录制时长为0(不限时长) strFileBMP = App.Path & "\TEMP\TMP.BMP" '保存的图片文件名 strFileAVI = App.Path & "\TEMP\TMP.AVI" '保存的视频文件名 Me.sbStatusBar.Panels(1).Text = "摄像头版本:" & _ frmCamera.ezVidCap1.GetDriverVersion() '在状态栏显示摄像头型号 Load frmCamera '载入摄像头窗体 frmCamera.ezVidCap1.TimeLimitEnabled = False '禁止摄像头控件的录取时间限制 frmCamera.Hide '隐藏摄像头窗体 Load frmVideo '载入预览窗体 frmVideo.Show '显示预览窗体 mnuPre1.Checked = True '选中预览菜单 Me.tbToolBar.Buttons(1).Value = tbrPressed '设置“预览”按钮为按下状态 End Sub

一个驱动webcam的类,利用通用的摄像头驱动程序avicap32.dll vb.net 选择自 xiaoyicn 的 Blog

---------------------------------------------------------Code By Ken Tucker-----------------------------------------------------------------------------------------------------------------------

明天就大了 1145

无驱摄像头黑屏问题解决办法

无驱摄像头黑屏问题解决办法,QQ中使用无驱动摄像头时,出现黑屏,无图像,轻松解决

C#摄像头编程

这段时间搞视频采集方面的程序,在国外网站上找到一个用C#写的驱动摄像头的程序。 经改造和调试,如下: (1)安装摄像头后,一般可以找到一个avicap32.dll文件 (2)这是一个关于摄像头的类: 复制  保存using System;using System.Runtime.InteropServices;namespace webcam{ ///

gaoyuchuan_IT的专栏 880

C#调用AForge、avicap32、platedsp方式打开摄像头

收集了通过调用 AForge、avicap32、platedsp方式 来打开摄像头,实现相应的应用,方便大家使用

C#调用avicap32.dll摄像头录制视频 ffmpeg压缩

基于avicap32.dll调用摄像头录制视频 实现监控功能,ffmpeg进行压缩,完整可运行

用C#捕获摄像头

作者:赤色火焰 转自:http://www.cnblogs.com/mgod/archive/2008/06/18/1224351.html 现在很多摄像头都是无驱动的,这种方法我试验没有成功,不知道各位高人有没有这方面的经验,网上也一直再问如何做视频录像,有知道的朋友麻烦给个参考地址。 文章最后提供了一个这个小程序的下载 (1)安装摄像头后,一般可以找到一个avica

老瓦的笔记本 990

无驱免驱摄像头显示黑屏解决办法说明和补丁

压缩包内有详细说明和补丁文件,可解决现象如下: 现象1:在“我的电脑”里能看到摄像头设备,但打开画面却是黑的,或qq、MSN、聊天室里等视频框黑屏,有时候拨掉摄像头重新再插上可以解决,有时候怎么弄都不行。 现象2:或者在amcap软件中能够正确显示,但一用qq就显示黑屏。 现象3:点击“我的电脑”中的USB视频设备会跳出“未能创建视频预览。请检查设备连接,确定没有其它应用程序或用户使用该设备。”的提示框。 现象4:打开摄像头,发现画面显示是纯黑的,我以为摄像头有问题,就随便点了下拍照,但是能拍下照片,跟别人qq视频也没问题,好好的,就是自己自拍的时候看不到,是黑屏的。

视频控件VideoCapX的使用指南和常见问题合集

VideoCapX控件可使开发者轻松地在数字视频撷取卡和相机中添加应用程序。不论你是创建多媒体播放器,数字录像机,电视协调器,网络摄像机,网络安全性程序、身份证数据库、工业监视系统、还是医学成像设备,VideoCapX都可以帮您捕捉和保存这些图像和视频序列。 一、播放MP4、H264、MOV、AVC文件 VideoCapX支持播放MP4、...

weixin_34216196的博客 1301

UHPC的疲劳计算——兼论ModelCode2010的适用性

ModelCode2010的混凝土疲劳计算方法是适用于UHPC的。

George的博客 1335

华为鸿蒙系统也能用!5分钟搞定谷歌三件套安装(附最新APK下载链接)

本文为华为鸿蒙系统用户提供了一份详尽的谷歌三件套(Google Play服务、商店及框架)手动安装指南。文章核心在于无需Root,通过ADB命令获取设备信息,并从可靠来源下载匹配版本的APK,按照正确顺序安装,从而解决海外应用依赖问题,实现5分钟快速部署。

c7d8e9的博客 6844

简述VB.NET中用OPENCV来处理摄像头拍摄图像的畸变

这几天在做一个双目视觉的东西,要达到深度识别0.1mm以内,没深入过这方面的东西,边学边记录。所以,这一篇代码非常简单和粗鄙,甚至需要你自己修改很多东西才能运行。 使用OPENCV来进行矫正图像,首先要得到两个矩阵:相机矩阵、畸变矩阵。然后使用InitUndistortRectifyMap、Remap函数来处理就可以得到矫正后的图像。 一、软件准备 1、NuG...

zcsor的专栏 2608

STM32F103单片机驱动TM1637数码管显示模块

最近项目中需要用到数码管显示,于是买了一个TM1637芯片驱动的四位数码显示模块,现将调试过程记录一下,方便以后参考。 使用的单片机是STM32F103C8T6最小系统 使用的数码管模块是TM1637四位数码管显示模块 实际运行效果 下面先看一下TM1637和数码管连接的具体线路图 实际使用的模块没有带按键,只用了4个数码管,模块和单片机连接只需要4根线VCC、GND、CLK、DIO。芯片和单片机通信使用的是I2C总线,下面就来说一下如何...

HXYDJ的博客 1万+
上一篇: 用VS.NET2003制作WEB应用程序的安装包
下一篇: 在Asp.net中如何实现弹出提示对话框()
ytbada
博客等级 码龄24年 361粉丝 221原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值