Image and AVI Capture This programming example (VB.NET) shows how to capture AVI files and JPEG images using IC Imaging Control simultaneously.
Language: | .NET C#/Visual Basic
Version: | 3.3
Author: | IC Imaging Control Support Department
Requirements: |
Software: | IC Imaging Control 3.3, Visual Studio™ 2010
Hardware: | Camera, converter or grabber with WDM Stream Class drivers.
Download VB NET sample | Image and AVI Capture - VB NET

This problem is solved using a special frame filter that saves images to JPEG files. The frame filter is included in the sample's setup file. Following functionallity is implemented in the sample:

- Open and setup a video capture device using IC Imaging Control's built-in dialogs.
- Save the currently used video capture and load the last used video capture device at program start.
- Resize the live video to IC Imaging Control's window size.
- List all available codecs in a combo box.
- If available, then show the codec's property dialog.
- Pause and continue AVI Capture.
- Snap and save images while AVI files are captured.

Most of the listed tasks are explained in the other samples of the code library. Thus only the use of the "Save Image" frame filter will be explained. First of all a variable of type TIS.Imaging.FrameFilter is to be declared on top of the form. This variable is named SnapImageFilter and will be used for accessing the frame filter for image saving.

    VB.NET

    Dim SnapImageFilter As TIS.Imaging.FrameFilter

The "Save Image" filter will be loaded in the Form1_load sub. After it has been tried to load the filter, the content of SnapImageFilter is checked whether it is Nothing. If SnapImageFilter is Nothing, the filter has not been loaded. This happens, if the filter file SaveImageFrameFilter.FTF is not located in the application's path. The frame filter is added to the solution. Its action property is set tp "Copy if newer", so the frame filter is copied to the application.

If the SnapImageFilter has been loaded successfully, it is inserted into the device path of IC Imaging Control.

    VB.NET

    SnapImageFilter = IcImagingControl1.FrameFilterCreate("Save Image", "")
    If SnapImageFilter Is Nothing Then
        MessageBox.Show("Failed to load the Snap Image filter", "Filter Loading", MessageBoxButtons.OK, MessageBoxIcon.Warning)
    Else
        IcImagingControl1.DeviceFrameFilters.Add(SnapImageFilter)
    End If

The images should be saved using a button on the application's form. Thus a button handler is to be inserted into the source code. There are some checks performed in the button handler btnSnapImage_Click before the image is saved:

- Is a valid video capture device loaded?
- Is the live video running?
- Is SnapImageFilter not Nothing?

The parameter "ImageName" of the SnapImageFilter must be set to a valid file name. This causes the SnapImageFilter to save an image. Since this is a parameter transfer between the application's thread and the IC Imaging Control video thread, this must be set into BeginParameterTransfer and EndParameterTransfer calls. The SnapImageFilter will capture the next incoming image after the parameter "ImageName" has been set.

    VB.NET

    Private Sub btnSnapImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSnapImage.Click
        With IcImagingControl1
            If .DeviceValid = True Then
                If .LiveVideoRunning = True Then
                    If Not SnapImageFilter Is Nothing Then
                        ImageCounter = ImageCounter + 1
                        Dim ImageFileName As String
                        ImageFileName = String.Format("Image{0}.jpg", ImageCounter)
                        SnapImageFilter.BeginParameterTransfer()
                        ' Passing the image name to the SnapImageFilter will snap the image
                        SnapImageFilter.SetStringParameter("ImageName", ImageFileName)
                        SnapImageFilter.EndParameterTransfer()
                    End If
                End If
            End If
        End With
    End Sub