扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
给你个工程自己看...
10余年的盐津网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整盐津建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联公司从事“盐津网站设计”,“盐津网站推广”以来,每个客户项目都认真落实执行。
运行后可以看到自己...
点按钮保存到c:\1.bmp
Private Const WS_CHILD = H40000000
Private Const WS_VISIBLE = H10000000
Private Const WM_CAP_START = H400
Private Const WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10
Private Const WM_CAP_SET_SCALE = WM_CAP_START + 53
Private Const WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52
Private Const WM_CAP_SET_PREVIEW = WM_CAP_START + 50
Private Declare Function capCreateCaptureWindowA Lib "avicap32.dll" ( _
ByVal lpszWindowName As String, _
ByVal dwStyle As Long, _
ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Integer, _
ByVal hWndParent As Long, ByVal nID As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
Private Sub Form_Load()
'建立采集窗口(不显示窗口,处理后显示到PIC控件)
uwndc = capCreateCaptureWindowA("", WS_VISIBLE Or WS_CHILD, 0, 0, 320, 240, Me.hWnd, 0)
'连接
SendMessage uwndc, WM_CAP_DRIVER_CONNECT, 0, 0
'Scale开
SendMessage uwndc, WM_CAP_SET_SCALE, True, 0
'显示刷新MS
SendMessage uwndc, WM_CAP_SET_PREVIEWRATE, 40, 0
'用予览方式显示(特殊需要,不显示予缆)
SendMessage uwndc, WM_CAP_SET_PREVIEW, True, 0
End Sub
上述代码就可以实现 但是要注意相应的控件是否存在 不存在的 你自己画出来
这个方法没问题。
win8.1,我用网上的方法,有时也有黑屏现象,但多试几次就好了。有时还会弹出要选择摄像头,选择确认、取消、应用都是黑屏。
所谓 API,全称叫 Application Programming Interface(应用程序编程接口),是一些预先定义的函数,目的是提供应用程序与开发人员基于某软件或硬件的以访问一组例程的能力,而又无需访问源码,或理解内部工作机制的细节。
通常在 WIndows 编程中称呼的 API ,一般指的是 Windows API,也就是 WIndows 操作系统提供给我们的函数,这些函数被封装在 C:\Windows\system32\ 下面的一个个 DLL 文件中。
所以调用什么 API 取决于调用的是哪个 DLL,跟 XP 不 XP 的没有一毛钱关系。
windows照片查看器调用的是PhotoViewer.dll,但没有提供com接口,vb.net本身已经自带Picturebox控件
下面是我之前在VB6里测试过的代码:在窗体里放一个按钮叫Command1和一个PictureBox叫Picture1。 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 Private Const WS_CHILD = H40000000 Private Const WS_VISIBLE = H10000000 Private Const WM_USER = H400 Private Const WM_CAP_START = H400 Private Const WM_CAP_EDIT_COPY = (WM_CAP_START + 30) Private Const WM_CAP_DRIVER_CONNECT = (WM_CAP_START + 10) Private Const WM_CAP_SET_PREVIEWRATE = (WM_CAP_START + 52) Private Const WM_CAP_SET_OVERLAY = (WM_CAP_START + 51) Private Const WM_CAP_SET_PREVIEW = (WM_CAP_START + 50) Private Const WM_CAP_DRIVER_DISCONNECT = (WM_CAP_START + 11) 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 SendMessageAsLong Lib "user32" Alias "SendMessageA" _ (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long) As Long Private Preview_Handle As Long Private iDevice As Long Private hHwnd As Long Private Sub Command1_Click() Dim bRet As Boolean Dim szTest As String szTest = App.Path "\TEST.bmp" Chr$(0) bRet = capEditCopy(hHwnd) If bRet Then DoEvents If Clipboard.GetFormat(vbCFBitmap) Then Picture1.Picture = Clipboard.GetData(vbCFBitmap) Picture1.Picture = Clipboard.GetData(vbCFBitmap) SavePicture Picture1.Image, szTest DoEvents Clipboard.Clear End If End If End Sub Private Sub Form_Load() '建立捕获窗口 Preview_Handle = capCreateCaptureWindow("Video", WS_CHILD + WS_VISIBLE, 0, 0, 320, 240, Me.hWnd, 1) '建立捕获窗口到捕获设备的连接 SendMessage Preview_Handle, WM_CAP_DRIVER_CONNECT, 0, 0 '设置捕获的帧频率为30毫秒一帧 SendMessage Preview_Handle, WM_CAP_SET_PREVIEWRATE, 30, 0 '用预览模式在捕获窗口开始预览图像 SendMessage Preview_Handle, WM_CAP_SET_PREVIEW, 1, 0 End Sub Private Sub Form_Unload(Cancel As Integer) '断开到捕获设备的连接 SendMessage Preview_Handle, WM_CAP_DRIVER_DISCONNECT, 0, 0 End Sub Private Function capEditCopy(ByVal hCapWnd As Long) As Boolean capEditCopy = SendMessageAsLong(hCapWnd, WM_CAP_EDIT_COPY, 0, 0) End Function
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流