使用avicap32.dll调用摄像头,解决黑屏问题,重新封装了一个新的dll

本文介绍了在使用avicap32.dll调用摄像头时遇到的黑屏问题,特别是在Windows 7及更高版本系统中。作者通过重新封装类库,实现了启动摄像头、动态预览、实时抓图和获取分辨率等功能,解决了这一问题。如有需要dll文件,可留言或联系5745519@qq.com。
摘要由CSDN通过智能技术生成

最近用avicap32.dll调用摄像头,XP下正常,在win7及以上系统中,黑屏。试着捕获图片,有时可成功。我只要捕获图片,故可另辟蹊径,重写了一个类库,实现了启动摄像头、动态预览、实时抓图、获取分辨率和支持分辨率的功能,并简化了操作。要dll的留言,或5745519@qq.com

Dim l As Camera
Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Left = (Screen.PrimaryScreen.WorkingArea.Width - Me.Width) / 2 '使窗口位于屏幕中间
        Me.Top = (Screen.PrimaryScreen.WorkingArea.Height - Me.Height) / 3 '使窗口位于屏幕高度的1/3
        l = New Camera(Me, Me.PictureBox3)
        sccess = l.RunCam()
        If sccess Then
            Dim fbl As String() = l.GetResolution
            For Each f As String In fbl
                Me.CB_fbl.Items.Add(f)
            Next
            Me.CB_fbl.SelectedIndex = 0
            Me.CB_fbl.Text = Getini("fbl", Me.CB_fbl.Text, mpath)
        End If
    End Sub

Private Sub Button_capture_Click(B
#region 导入API函数 [DllImport("avicap32.dll")]//包含了执行视频捕获的函数,它给AVI文件I/O和视频、音频设备驱动程序提供一个高级接口 public static extern IntPtr capCreateCaptureWindow(string lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hwndParent, int nID); /************参数说明************* * * 函数:capCreateCaptureWindow * * lpszWindowName:标识窗口的名称 * dwStyle:标识窗口风格 * x、y:标识窗口的左上角坐标 * nWidth、nHeight:标识窗口的宽度和高度 * hWnd:标识父窗口句柄 * nID:标识窗口ID * * 返回值:视频捕捉窗口句柄。 * ********************************/ [DllImport("AVICAP32.dll", CharSet = CharSet.Unicode)] public static extern bool capGetDriverDescription(int wDriverIndex, StringBuilder lpszName, int cbName, StringBuilder lpszVer, int cbVer); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, bool wParam, int lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, short wParam, int lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, short wParam, FrameEventHandler lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, ref BITMAPINFO lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, ref CAPDRIVERCAPS lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, ref CAPTUREPARMS lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, ref CAPSTATUS lParam); [DllImport("User32.dll")] public static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags); [DllImport("avicap32.dll")] public static extern int capGetVideoFormat(IntPtr hWnd, IntPtr psVideoFormat, int wSize); #endregion
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值