我感到很惭愧,但无论如何我会问:从网络摄像头拍摄照片的最简单方法是使用默认尺寸和颜色深度?
我开始玩DirectShowLib,但我一无所知......有人可以给我一个指导吗?
Imports DirectShowLib
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
PictureBox1.Image = Nothing
Dim Cam As DsDevice = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice).FirstOrDefault
If Cam IsNot Nothing Then
Stop
' ... what now?
End If
End Sub
End Class
答案 0 :(得分:1)
DirectShowLib' s samples DxSnap,DxWebCam(C#)展示如何从网络摄像头捕获。那里还有VB.NET DxLogoVB,它做了不同的事情但是如果你还要查找一些DriectShow.NET + VB.NET示例代码仍然很好。
DxWebCam:
一个穷人的网络摄像头程序。此应用程序作为Win32服务运行 它获取捕获图的输出,将其转换为JPEG流 文件,并通过TCP / IP将其发送到客户端应用程序。
DxSnap:
使用DirectShow从捕获的Still引脚获取快照 设备。请注意MS鼓励您使用WIA,但是如果 你想用DirectShow和C#做什么,这里是怎么做的。
请注意,此示例仅适用于输出未压缩的设备 视频为RBG24。这将包括大多数网络摄像头,但可能是零电视调谐器。
答案 1 :(得分:0)
好的,我能做的最好取决于AForge.Controls和AForge.Video.DirectShow并正在使用这个代码,我打算改进它(这是一个粗略的划痕 - 但是拍照):
Public Class Form1
Private Sub Test() Handles Me.Load
Dim rf As New RolleiFlex
PictureBox1.Image = rf.Click
End Sub
End Class
Public Class RolleiFlex
Public Sub New()
Dim vDevices = New AForge.Video.DirectShow.FilterInfoCollection(FilterCategory.VideoInputDevice)
Devices = vDevices.Cast(Of FilterInfo).Select(
Function(fi) New Device With {
.Name = fi.Name,
.MonikerString = fi.MonikerString}).ToArray
SelectedDevice = Devices.FirstOrDefault
vDevices = Nothing
End Sub
Public Devices As Device()
Public Property SelectedDevice As Device
Public Class Device
Public Property Name As String
Public Property MonikerString As String
End Class
Public Function Click() As Bitmap
Dim retBmp As Bitmap
Dim camera As New AForge.Controls.VideoSourcePlayer
camera.VideoSource = New VideoCaptureDevice(SelectedDevice.MonikerString)
camera.Start()
Do
retBmp = camera.GetCurrentVideoFrame
If retBmp Is Nothing Then Threading.Thread.Sleep(100)
Loop While retBmp Is Nothing
camera.Stop()
camera.Dispose()
camera = Nothing
Return retBmp
End Function
End Class