[英]Capture still image from webcam (DirectSHowLib, VB.NET)
我很as愧,但無論如何我都會問:這是從具有默認大小和色深的網絡攝像頭拍攝照片的最直接方法嗎?
我開始玩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
DirectShowLib的示例 DxSnap,DxWebCam(C#)顯示了如何從網絡攝像頭捕獲。 這里也有VB.NET DxLogoVB,它做的是不同的事情,但是如果您還尋找一些DriectShow.NET + VB.NET示例代碼,它仍然很好。
DxWebCam:
一個窮人的網絡攝像頭程序。 此應用程序作為Win32服務運行。
它獲取捕獲圖的輸出,將其轉換為JPEG文件流 ,然后通過TCP / IP將其發送到客戶端應用程序。
DxSnap:
使用DirectShow從捕獲設備的“ Still”引腳拍攝快照。 請注意,MS鼓勵您為此使用WIA,但是如果要使用DirectShow和C#,請按以下步驟操作。
請注意,此示例僅適用於將未壓縮視頻輸出為RBG24的設備。 這將包括大多數網絡攝像頭,但可能包括零個電視調諧器。
好的,我能做的最好的取決於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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.