最近做了一个SilverLight摄像头捕获图像案例,贴一下给大家:
'打开电脑摄像头
Private Sub BtnCamClick(ByVal sender As Object, ByVal e As RoutedEventArgs)
'取得默认视频捕获设备
Dim cam As VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice
'视频或者音频捕获资源
Dim captureSource As New CaptureSource
If CaptureDeviceConfiguration.RequestDeviceAccess() Then
'要捕获的视频设备
captureSource.VideoCaptureDevice = cam
'VideoBrush的Source来源
myVideoBrush.SetSource(captureSource)
myVideoBrush.Stretch = Stretch.Fill
'开始捕获方法
captureSource.Start()
End If
Me.btnCam.IsEnabled = False
End Sub
'捕获图像源码
Private Sub BtnImageClick(ByVal sender As Object, ByVal e As RoutedEventArgs)
'使用WriteableBitMap来捕获视频区域控件图像
Dim stream As WriteableBitmap = New WriteableBitmap(Me.MyBorder, New MatrixTransform())
Me.imageTest.Source = stream
End Sub