VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)

VB爱好者乐园(VBGood)

 找回密码
 立即注册
搜索
查看: 4548|回复: 1

[求助] VB通过笔记本自带摄像头截图为黑屏

[复制链接]
 楼主| 发表于 2012-5-10 16:53:12 | 显示全部楼层 |阅读模式
代码如下, VB调用自带摄像头 ,下面代码,第一次运行的时候是有画面的,第二次以后,画面一直是黑屏,什么情况??

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function capCreateCaptureWindow Lib "avicap32.dll" Alias "capCreateCaptureWindowA" (ByVal lpszWindowName As String, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hwndParent As Long, ByVal nID As Long) As Long
Dim ctCapWin As Long



Private Sub Command1_Click()
'创建视频窗口和连接摄像头
    Const WS_Child = &H40000000:
    Const WS_Visible = &H10000000
    Const WS_Caption = &HC00000:
    Const WS_ThickFrame = &H40000
    Dim nStyle As Long, T As Long
   
    '创建一个视频窗口,大小:640*480
    If ctCapWin = 0 Then
        T = Me.ScaleY(Command1.Top + Command1.Height * 1.1, Me.ScaleMode, 3) '视频窗口垂直位置:像素
        nStyle = WS_Child + WS_Visible + WS_Caption + WS_ThickFrame '子窗口(在Form1内)+可见+标题栏+边框
        'nStyle = WS_Child + WS_Visible '视频窗口无标题栏和边框
        'nStyle = WS_Visible '视频窗口为独立窗口,关闭主窗口视频窗口也会自动关闭
        ctCapWin = capCreateCaptureWindow("我创建的视频窗口", nStyle, 0, T, 640, 480, Me.hWnd, 0)
        
   
    End If
   
    '将视频窗口连接到摄像头,如无后面两条语句视频窗口画面不会变化
    SendMessage ctCapWin, &H400 + 10, 0, 0 '连接摄像头
    SendMessage ctCapWin, &H400 + 50, 1, 0 '第三个参数:1-预览模式有效,0-预览模式无效
    SendMessage ctCapWin, &H400 + 52, 30, 0 '第三个参数:设置预览显示频率为每秒 30 帧

End Sub

Private Sub Command2_Click()
SendMessage ctCapWin, &H400 + 11, 0, 0 '断开摄像头连接
End Sub

Private Sub Command3_Click()
Const WM_Close = &H10
   SendMessage ctCapWin, WM_Close, 0, 0 '关闭视频窗口
   ctCapWin = 0                         '将视频窗口句柄设为 0

End Sub

Private Sub Form_Load()
   Dim H1 As Long
   Me.Caption = "摄像头控制":
   Command1.Caption = "连接摄像头"
   Command2.Caption = "断开摄像头":
   Command3.Caption = "关闭视频窗口"
   H1 = Me.TextHeight("A")
   Command1.Move H1 * 0.5, H1 * 0.5, H1 * 7, H1 * 2
   Command2.Move H1 * 8, H1 * 0.5, H1 * 7, H1 * 2
   Command3.Move H1 * 16, H1 * 0.5, H1 * 7, H1 * 2

End Sub
发表于 2013-2-17 18:54:37 | 显示全部楼层
为什么没人知道哦?同问哦
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

文字版|手机版|小黑屋|VBGood  

GMT+8, 2022-1-21 13:22

VB爱好者乐园(VBGood)
快速回复 返回顶部 返回列表