我需要VB代码程序显示我的网络摄像头的图片. [英] I need VB code program display the picture that my web cam..

查看:258
本文介绍了我需要VB代码程序显示我的网络摄像头的图片.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的CodeProject成员
我需要VB代码程序显示网络摄像头拍摄的图片,并在屏幕上高高显示它.
我正在等待您的帮助.
谢谢,再见

Dear CodeProject members
I need VB code program display the picture that my web cam takes it , and display its high and wide on the screen.
I am waiting your help .
Thanks and bye

推荐答案

构造WM​​_CAP为Short = 1024
常量WM_CAP_DRIVER_CONNECT为整数= WM_CAP + 10
常量WM_CAP_DRIVER_DISCONNECT为整数= WM_CAP + 11
常量WM_CAP_EDIT_COPY为整数= WM_CAP + 30
常量WM_CAP_SET_PREVIEW为整数= WM_CAP + 50
常量WM_CAP_SET_PREVIEWRATE为整数= WM_CAP + 52
常量WM_CAP_SET_SCALE为整数= WM_CAP + 53
const WS_CHILD作为整数= 1073741824
const WS_VISIBLE As Integer = 268435456
常量SWP_NOMOVE为Short = 2
常量SWP_NOSIZE为Short = 1
常量SWP_NOZORDER为Short = 4
常量HWND_BOTTOM为Short = 1
私有iDevice为Integer = Integer.Parse(0)
私有hHwnd作为整数
Private Sub frmWebCam_Load(ByVal发送者为System.Object,ByVal e为System.EventArgs)处理MyBase.Load
OpenPreviewWindow()
结束子

Const WM_CAP As Short = 1024
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 = 1073741824
Const WS_VISIBLE As Integer = 268435456
Const SWP_NOMOVE As Short = 2
Const SWP_NOSIZE As Short = 1
Const SWP_NOZORDER As Short = 4
Const HWND_BOTTOM As Short = 1
Private iDevice As Integer = Integer.Parse(0)
Private hHwnd As Integer
Private Sub frmWebCam_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OpenPreviewWindow()
End Sub

Private Sub OpenPreviewWindow()
       Dim iHeight As Integer = PBME.Height
       Dim iWidth As Integer = PBME.Width
       hHwnd = capCreateCaptureWindowA(iDevice.ToString(), (WS_VISIBLE Or WS_CHILD), 0, 0, 640, 480, PBME.Handle.ToInt32(), 0)
       If Sendweb(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) = 1 Then
           Sendweb(hHwnd, WM_CAP_SET_SCALE, 1, 0)
           Sendweb(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0)
           Sendweb(hHwnd, WM_CAP_SET_PREVIEW, 1, 0)
           SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, iWidth, iHeight, _
            (SWP_NOMOVE Or SWP_NOZORDER))
       Else
           DestroyWindow(hHwnd)
       End If
   End Sub



私有Sub Timer1_Tick(ByVal发送者作为System.Object,ByVal e作为System.EventArgs)处理tm.Tick
试试
昏暗ms =新的MemoryStream()
昏暗的数据作为IDataObject
昏暗的bmap作为图像
Sendweb(hHwnd,WM_CAP_EDIT_COPY,0,0)
数据= Clipboard.GetDataObject()
如果data.GetDataPresent(GetType(System.Drawing.Bitmap))然后
bmap = DirectCast(data.GetData(GetType(System.Drawing.Bitmap)),图片)
bmap.Save(ms,ImageFormat.Jpeg)
如果结束
异常捕获

结束尝试
结束Sub



Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tm.Tick
Try
Dim ms = New MemoryStream()
Dim data As IDataObject
Dim bmap As Image
Sendweb(hHwnd, WM_CAP_EDIT_COPY, 0, 0)
data = Clipboard.GetDataObject()
If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
bmap = DirectCast(data.GetData(GetType(System.Drawing.Bitmap)), Image)
bmap.Save(ms, ImageFormat.Jpeg)
End If
Catch ex As Exception

End Try
End Sub


这篇关于我需要VB代码程序显示我的网络摄像头的图片.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆