''' <summary>
''' Image capture source.
''' </summary>
Private _imageCaptureSource As Vintasoft.Imaging.Media.ImageCaptureSource
''' <summary>
''' Initializes a new instance of the <see cref="MainForm"/> class.
''' </summary>
Public Sub New()
InitializeComponent()
' get available image capture devices
Dim availableDevices As System.Collections.ObjectModel.ReadOnlyCollection(Of Vintasoft.Imaging.Media.ImageCaptureDevice) = Vintasoft.Imaging.Media.ImageCaptureDeviceConfiguration.GetCaptureDevices()
' create new image capture source
_imageCaptureSource = New Vintasoft.Imaging.Media.ImageCaptureSource()
AddHandler _imageCaptureSource.CaptureCompleted, New System.EventHandler(Of Vintasoft.Imaging.Media.ImageCaptureCompletedEventArgs)(AddressOf ImageCaptureSource_CaptureCompleted)
' if there are available devices
If availableDevices.Count <> 0 Then
' use the first image capture device
_imageCaptureSource.CaptureDevice = availableDevices(0)
End If
AddHandler Shown, New System.EventHandler(AddressOf MainForm_Shown)
AddHandler FormClosed, New System.Windows.Forms.FormClosedEventHandler(AddressOf MainForm_FormClosed)
End Sub
''' <summary>
''' Starts capturing from camera.
''' </summary>
Private Sub MainForm_Shown(sender As Object, e As System.EventArgs)
' if capture device is empty
If _imageCaptureSource.CaptureDevice IsNot Nothing Then
' start the image capture source
_imageCaptureSource.Start()
' initialize new image capture request
_imageCaptureSource.CaptureAsync()
End If
End Sub
''' <summary>
''' Image is captured.
''' </summary>
Private Sub ImageCaptureSource_CaptureCompleted(sender As Object, e As Vintasoft.Imaging.Media.ImageCaptureCompletedEventArgs)
' save reference to the previously captured image
Dim oldImage As Vintasoft.Imaging.VintasoftImage = imageViewer1.Image
' get captured image and show captured image in the image viewer
imageViewer1.Image = e.GetCapturedImage()
' if previously captured image exists
If oldImage IsNot Nothing Then
' dispose previously captured image
oldImage.Dispose()
End If
' if capture source is started
If _imageCaptureSource.State = Vintasoft.Imaging.Media.ImageCaptureState.Started Then
' initialize new image capture request
_imageCaptureSource.CaptureAsync()
End If
End Sub
''' <summary>
''' Form is closed.
''' </summary>
Private Sub MainForm_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs)
' stop the image capture source
_imageCaptureSource.[Stop]()
End Sub