将网络摄像头显示的视频中的图片保存在 VB6 的 PictureBox 中

发布于 2024-11-25 05:22:07 字数 2144 浏览 1 评论 0原文

我使用了来自互联网的代码以某种形式显示我的网络摄像头,但是,我不知道如何捕获图像并通过单击命令按钮将其自动保存到我的本地磁盘驱动器。有人能尽快帮助我吗:)) 这是我的表单代码。

    Option Explicit
Const ws_visible = &H10000000
Const ws_child = &H40000000
Const WM_USER = 1024
Const WM_CAP_EDIT_COPY = WM_USER + 30
Const wm_cap_driver_connect = WM_USER + 10
Const wm_cap_set_preview = WM_USER + 50
Const wm_cap_set_overlay = WM_USER + 51
Const WM_CAP_SET_PREVIEWRATE = WM_USER + 52
Const WM_CAP_SEQUENCE = WM_USER + 62
Const WM_CAP_SINGLE_FRAME_OPEN = WM_USER + 70
Const WM_CAP_SINGLE_FRAME_CLOSE = WM_USER + 71
Const WM_CAP_SINGLE_FRAME = WM_USER + 72
Const DRV_USER = &H4000
Const DVM_DIALOG = DRV_USER + 100
Const PREVIEWRATE = 30
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function capCreateCaptureWindow Lib "avicap32.dll" Alias "capCreateCaptureWindowA" (ByVal a As String, ByVal b As Long, ByVal c As Integer, ByVal d As Integer, ByVal e As Integer, ByVal f As Integer, ByVal g As Long, ByVal h As Integer) As Long

Dim hwndc As Long
Dim saveflag As Integer
Dim pictureindex As Integer
Dim filter1(-1 To 1, -1 To 1) As Single
Dim filter2(-1 To 1, -1 To 1) As Single
Dim temp As String

Private Sub Command2_Click()
Unload Me
Main.Show
End Sub

Private Sub Form_Load()
On Error GoTo handler:
hwndc = capCreateCaptureWindow("CaptureWindow", ws_child Or ws_visible, 0, 0,     Pichwnd.Width, Pichwnd.Height, Pichwnd.hWnd, 0)
If (hwndc <> 0) Then
    temp = SendMessage(hwndc, wm_cap_driver_connect, 0, 0)
    temp = SendMessage(hwndc, wm_cap_set_preview, 1, 0)
    temp = SendMessage(hwndc, WM_CAP_SET_PREVIEWRATE, PREVIEWRATE, 0)

    temp = SendMessage(Me.hWnd, WM_CAP_EDIT_COPY, 1, 0)
    Picture1.Picture = Clipboard.GetData
Else
    MsgBox "Unable to capture video.", vbCritical
End If
Exit Sub
handler:
End
End Sub
Private Sub Form_Initialize()
If Me.WindowState <> vbMaximized Then
    Me.WindowState = vbMaximized
Else
    Me.WindowState = vbNormal
End If
End Sub

我的代码可能太长,但我刚刚通过教程学习了一些 vb6,因为我需要为我的毕业项目制作一个 GUI。最后感谢您的帮助

I have used a code from the internet to show my webcam in a certain form, however, i dont know how to capture an image and save it automatically to my local disk drive via command button click. would anyone help me ASAP :))
here is my code for the form.

    Option Explicit
Const ws_visible = &H10000000
Const ws_child = &H40000000
Const WM_USER = 1024
Const WM_CAP_EDIT_COPY = WM_USER + 30
Const wm_cap_driver_connect = WM_USER + 10
Const wm_cap_set_preview = WM_USER + 50
Const wm_cap_set_overlay = WM_USER + 51
Const WM_CAP_SET_PREVIEWRATE = WM_USER + 52
Const WM_CAP_SEQUENCE = WM_USER + 62
Const WM_CAP_SINGLE_FRAME_OPEN = WM_USER + 70
Const WM_CAP_SINGLE_FRAME_CLOSE = WM_USER + 71
Const WM_CAP_SINGLE_FRAME = WM_USER + 72
Const DRV_USER = &H4000
Const DVM_DIALOG = DRV_USER + 100
Const PREVIEWRATE = 30
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function capCreateCaptureWindow Lib "avicap32.dll" Alias "capCreateCaptureWindowA" (ByVal a As String, ByVal b As Long, ByVal c As Integer, ByVal d As Integer, ByVal e As Integer, ByVal f As Integer, ByVal g As Long, ByVal h As Integer) As Long

Dim hwndc As Long
Dim saveflag As Integer
Dim pictureindex As Integer
Dim filter1(-1 To 1, -1 To 1) As Single
Dim filter2(-1 To 1, -1 To 1) As Single
Dim temp As String

Private Sub Command2_Click()
Unload Me
Main.Show
End Sub

Private Sub Form_Load()
On Error GoTo handler:
hwndc = capCreateCaptureWindow("CaptureWindow", ws_child Or ws_visible, 0, 0,     Pichwnd.Width, Pichwnd.Height, Pichwnd.hWnd, 0)
If (hwndc <> 0) Then
    temp = SendMessage(hwndc, wm_cap_driver_connect, 0, 0)
    temp = SendMessage(hwndc, wm_cap_set_preview, 1, 0)
    temp = SendMessage(hwndc, WM_CAP_SET_PREVIEWRATE, PREVIEWRATE, 0)

    temp = SendMessage(Me.hWnd, WM_CAP_EDIT_COPY, 1, 0)
    Picture1.Picture = Clipboard.GetData
Else
    MsgBox "Unable to capture video.", vbCritical
End If
Exit Sub
handler:
End
End Sub
Private Sub Form_Initialize()
If Me.WindowState <> vbMaximized Then
    Me.WindowState = vbMaximized
Else
    Me.WindowState = vbNormal
End If
End Sub

my code might be too long but i just learned some vb6 via tutorials as i need to make a GUI to my Grad project. Finally thanks for help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往事随风而去 2024-12-02 05:22:07

发送WM_CAP_FILE_SAVEDIB< /a> 向您的 hwndc 发送消息,其中包含要保存到的文件名。

更好的选择是使用 自行处理视频回调WM_CAP_SET_CALLBACK_FRAME消息或capVideoStreamCallback 回调功能。

另外,请查看 http://www.shrinkwrapvb.com/videocap.htm

请注意,VfW 捕获已非常过时,应替换为 Directshow(但在 VB6 中很难正确执行)

Send the WM_CAP_FILE_SAVEDIB message to your hwndc with the filename to save to.

A better option is to handle the video callbacks yourself with WM_CAP_SET_CALLBACK_FRAME message or the capVideoStreamCallback callback function.

Also, take a look at the examples at http://www.shrinkwrapvb.com/videocap.htm.

Note that VfW capture is very outdated and should be replaced with Directshow (but is very difficult to do properly in VB6)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文