LEAD Technologies, Inc

Creating a Basic LEADTOOLS Multimedia Capture Application

Take the following steps to create and run a multimedia capture application using the LEADTOOLS Multimedia CaptureCtrl control.

  1. Start Visual Studio .NET.
  2. Choose File->New->Project... from the menu.
  3. In the New Project dialog box, choose either "Visual C# Projects" or "Visual Basic Projects" in the Projects Type List, and choose "Windows Application " in the Templates List.
  4. Type the project name as "Multimedia Capture" in the Project Name field, and then choose OK. If desired, type a new location for your project or select a directory using the Browse button, and then choose OK.
  5. In the "Solution Explorer" window, right-click on the "References" folder, and select "Add Reference..." from the context menu. In the "Add Reference" dialog box, select the ".NET" tab and select Leadtools.Multimedia and click OK. If this dll does not appear under the .NET tab, you will need select the Browse tab and add it from the "<LEADTOOLS_INSTALLDIR>\Bin\DotNet\Win32 " folder, by selecting the following DLL:
    • Leadtools.Multimedia.dll
    After browsing, click the Select button and then press the OK button to add the above DLL to the application.
  6. Make sure Form1 is in design view. Go to the toolbox (View->Toolbox) and drag and drop a CaptureCtrl control on the form. NOTE: If you do not have CaptureCtrl in your toolbox, select Tools->Choose Toolbox Items from the menu. Click Browse and then select Leadtools.Multimedia.dll from "<LEADTOOLS_INSTALLDIR>\Bin\DotNet\Win32" and then click Open and then click OK. After adding it to the form, set the following properties on the capture control:
    Property Value
    Name _capturectrl
    Anchor Top, Bottom, Left, Right
  7. Go to the toolbox (View->Toolbox) and drag and drop a ProgressBar control on the form (below the capture control) and set the following properties:
    Property Value
    Name _progress
    Anchor Bottom, Left, Right
  8. Go to the toolbox (View->Toolbox) and drag and drop a Button control on the bottom of the form and set the following properties:
    Property Value
    Name _buttonCapture
    Text Capture
    Anchor Bottom, Right
  9. Switch Form1 to code view (right-click Form1 in the solution explorer then select View Code) and add the following lines at the beginning of the file:

    [Visual Basic]
                Imports Leadtools.Multimedia
                
    
    [C#]
                using Leadtools.Multimedia;
                
    
  10. Declare the following private variables:

    [Visual Basic]
                Private _targetFile As String
                Private _captureTime As Integer
                
    
    [C#]
                private string _targetFile;
                private int _captureTime;
                
    
  11. Add an event handler to the Form1 Load event and code it as follows:

    [Visual Basic]
                Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                   If (_capturectrl.VideoDevices.Count = 0) Then
                      Throw New Exception("No capture devices available")
                   End If
                      
                   _capturectrl.VideoDevices(0).Selected = True
                   _capturectrl.VideoCompressors.Mpeg2.Selected = True
                   
                   _targetFile = "capture.avi"
                   _captureTime = 30
                End Sub
                
    
    [C#]
                private void Form1_Load(object sender, System.EventArgs e)
                {
                   if (_capturectrl.VideoDevices.Count == 0)
                      throw new Exception("No capture devices available");
                      
                   _capturectrl.VideoDevices[0].Selected = true;
                   _capturectrl.VideoCompressors.Mpeg2.Selected = true;
                   
                   _targetFile = "capture.avi";
                   _captureTime = 30;
                }
                
    
  12. Add an event handler to the _capturectrl Progress event and code it as follows:

    [Visual Basic]
                Private Sub _capturectrl_Progress(ByVal sender As System.Object, ByVal e As ProgressEventArgs) Handles _capturectrl.Progress
                   _progress.Value = CInt((_progress.Maximum * e.time) / (_captureTime * 1000))
                End Sub
                
    
    [C#]
                private void _capturectrl_Progress(object sender, ProgressEventArgs e)
                {
                   _progress.Value = (int)((_progress.Maximum * e.time) / (_captureTime * 1000));
                }
                
    
  13. Add an event handler to the _capturectrl Complete event and code it as follows:

    [Visual Basic]
                Private Sub _capturectrl_Complete(ByVal sender As System.Object, ByVal e As EventArgs) Handles _capturectrl.Complete
                   MessageBox.Show("Capture Complete")
                   _buttonCapture.Enabled = True
                End Sub
                
    
    [C#]
                private void _capturectrl_Complete(object sender, EventArgs e)
                {
                   MessageBox.Show("Capture Complete");
                   _buttonCapture.Enabled = true;
                }
                
    
  14. Add an event handler to the _buttonCapture Click event and code it as follows:

    [Visual Basic]
                Private Sub _buttonCapture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _buttonCapture.Click
                   Try
                      _capturectrl.Preview = True
                      _capturectrl.TargetFile = _targetFile
                      _capturectrl.UseTimeLimit = True
                      _capturectrl.TimeLimit = _captureTime
                      
                      _capturectrl.StartCapture(CaptureMode.Video)
                      _buttonCapture.Enabled = False
                   Catch ex As Exception
                      MessageBox.Show(ex.Message)
                   End Try
                End Sub   
                
    
    [C#]
                private void _buttonCapture_Click(object sender, System.EventArgs e)
                {
                   try
                   {
                      _capturectrl.Preview = true;
                      _capturectrl.TargetFile = _targetFile;
                      _capturectrl.UseTimeLimit = true;
                      _capturectrl.TimeLimit = _captureTime;
                      
                      _capturectrl.StartCapture(CaptureMode.Video);
                      _buttonCapture.Enabled = false;
                   }
                   catch (Exception ex)
                   {
                      MessageBox.Show(ex.Message);
                   }
                }
                
    
  15. Build, and Run the program to test it.

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.