Perform the following steps to create and run a multimedia capture application using the LEADTOOLS Multimedia CaptureCtrl control.
In the "Solution Explorer" window, right-click "References" and choose "Add Reference..." from the context menu. In the "Add Reference" dialog box, click the ".NET" tab, select Leadtools.Multimedia and click OK. If this DLL does not appear under the .NET tab, click the Browse tab, navigate to the "<LEADTOOLS_INSTALLDIR>\Bin\Dotnet4\Win32" folder, and select the following DLL:
Click OK to add the above DLL to the application.
Make sure Form1 is in design view. Go to the toolbox (View->Toolbox) and drag a CaptureCtrl control on the form. NOTE: If you do not have CaptureCtrl in your toolbox, open the Tools menu and then choose Choose Toolbox Items from the menu. In the Reference Manager dialog, click Browse, navigate to the "<LEADTOOLS_INSTALLDIR>\Bin\Dotnet4\Win32" directory and then select Leadtools.Multimedia.dll. Click OK. After adding the control to the form, set the following properties for the capture control:
Property | Value |
---|---|
Name | _capturectrl |
Anchor | Top, Bottom, Left, Right |
Go to the toolbox (View->Toolbox) and drag a ProgressBar control on the form (below the capture control) and set the following properties:
Property | Value |
---|---|
Name | _progress |
Anchor | Bottom, Left, Right |
Go to the toolbox (View->Toolbox) and drag a Button control on the bottom of the form and set the following properties:
Property | Value |
---|---|
Name | _buttonCapture |
Text | Capture |
Anchor | Bottom, Right |
Switch Form1 to code view (right-click Form1 in the Solution Explorer, then choose View Code) and add the following lines to the beginning of the file:
Imports Leadtools.Multimedia
using Leadtools.Multimedia;
Declare the following private variables:
Private _targetFile As String
Private _captureTime As Integer
private string _targetFile;
private int _captureTime;
Add an event handler to the Form1 Load event and code it as follows:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Note: Modify and uncomment the following line to remove the pop-up "NAG" dialog
'Leadtools.Multimedia.Common.MultimediaSupport.UnlockModule("YOUR LTMM KEY",Leadtools.Multimedia.Common.LockType.Application, "YOUR APPLICATION ID")
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
private void Form1_Load(object sender, System.EventArgs e)
{
//Note: Modify and uncomment the following line to remove the pop-up "NAG" dialog
//Leadtools.Multimedia.Common.MultimediaSupport.UnlockModule("YOUR LTMM KEY", Leadtools.Multimedia.Common.LockType.Application, "YOUR APPLICATION ID");
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;
}
Add an event handler to the _capturectrl Progress event and code it as follows:
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
private void _capturectrl_Progress(object sender, ProgressEventArgs e)
{
_progress.Value = (int)((_progress.Maximum * e.time) / (_captureTime * 1000));
}
Add an event handler to the _capturectrl Complete event and code it as follows:
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
private void _capturectrl_Complete(object sender, EventArgs e)
{
MessageBox.Show("Capture Complete");
_buttonCapture.Enabled = true;
}
Add an event handler to the _buttonCapture Click event and code it as follows:
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
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);
}
}
Build, and Run the program to test it.