Creating a LEADTOOLS Multimedia Conversion Application using Processors

Summary

Perform the following steps to create and run a multimedia conversion application with processors using the LEADTOOLS Multimedia ConvertCtrl control.

  1. Start Visual Studio .NET 2010.

  2. Choose File->New->Project... from the main menu.

  3. In the New Project dialog box, choose either "Visual C# Projects" or "VB Projects" in the Projects Type List, and select "Windows Forms Application" in the Templates List.

  4. Type the project name as Multimedia Conversion with Processors in the Project Name field, and if desired, type a new location for your project or navigate to a directory using the Browse button, and then click OK.

  5. In the Solution Explorer window, right-click 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, click the Browse tab and navigate to the "<LEADTOOLS_INSTALLDIR>\Bin\Dotnet\Win32" folder, and select the following DLL:

    • Leadtools.Multimedia.dll

    With the DLL selected, click OK to add the DLL to the application.

  6. Make sure Form1 is in design view. Go to the toolbox (View->Toolbox) and drag a ConvertCtrl control onto the form.

    NOTE: If you do not have the ConvertCtrl in your toolbox, open the main menu and choose Tools->Choose Toolbox Items from the menu. Click the Browse tab and navigate to the "<LEADTOOLS_INSTALLDIR>\Bin\Dotnet\Win32" folder and select Leadtools.Multimedia.dll and click OK. After adding it to the form, set the following properties on the convert control:

    Property Value
    Name _convertctrl
    Anchor Top, Bottom, Left, Right
    BackColor Black
  7. Go to the toolbox (View->Toolbox) and drag a ProgressBar control onto the form (below the ConvertCtrl) and set the following properties:

    Property Value
    Name _progress
    Anchor Bottom, Left, Right
    Step 1
  8. Go to the toolbox (View->Toolbox) and drag two Button controls to the bottom of the form and set the following properties:

    Property Value
    Name _buttonProcessor
    Text Processor...
    Anchor Bottom, Right
  9. 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:

    C#
    VB
    Imports Leadtools.Multimedia

    **[C#] **

    using Leadtools.Multimedia;

  10. Declare the following private variable:

    C#
    VB
    Private _sourceFile As String 
    Private _targetFile As String 
    Private _addedProc As Boolean 
    private string _sourceFile; 
    private string _targetFile; 
    private bool _addedProc; 

  11. Add an event handler to the Form1 Load event and code it as follows:

    C#
    VB
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
       _sourceFile = @"<LEADTOOLS_INSTALLDIR>\Media\DaDa_DVD_MPEG2.mpg" 
       _targetFile = "DaDa_MJPEG_Deinterlaced.avi" 
       _addedProc = False 
    End Sub 
    private void Form1_Load(object sender, System.EventArgs e) 
    { 
       _sourceFile = @"<LEADTOOLS_INSTALLDIR>\Media\DaDa_DVD_MPEG2.mpg"; 
       _targetFile = "DaDa_MJPEG_Deinterlaced.avi"; 
       _addedProc = false; 
    } 

  12. Add an event handler to the _convertctrl Progress event and code it as follows:

    C#
    VB
    Private Sub _convertctrl_Progress(ByVal sender As System.Object, ByVal e As ProgressEventArgs) Handles _convertctrl.Progress 
       _progress.Value = CInt((_progress.Maximum * e.percent / 100)) 
    End Sub 
    private void _convertctrl_Progress(object sender, ProgressEventArgs e) 
    { 
       _progress.Value = (int)(_progress.Maximum * e.percent / 100); 
    } 

  13. Add an event handler to the _convertctrl Complete event and code it as follows:

    C#
    VB
    Private Sub _convertctrl_Complete(ByVal sender As System.Object, ByVal e As EventArgs) Handles _convertctrl.Complete 
       MessageBox.Show("Conversion Complete") 
       _buttonProcessor.Enabled = True 
       _buttonConvert.Enabled = True 
    End Sub 
    private void _convertctrl_Complete(object sender, EventArgs e) 
    { 
       MessageBox.Show("Conversion Complete"); 
       _buttonProcessor.Enabled = true; 
       _buttonConvert.Enabled = true; 
    } 

  14. Add an event handler to the _buttonProcessor Click event and code it as follows:

    C#
    VB
    Private Sub _buttonProcessor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _buttonProcessor.Click 
       Try 
         Dim deinterlace As Processor = _convertctrl.VideoProcessors.Deinterlace 
         Dim procName As String = deinterlace.Name 
         If (_addedProc = False) Then 
             _convertctrl.SelectedVideoProcessors.Add(deinterlace) 
             _addedProc = True 
         End If 
         If (_convertctrl.SelectedVideoProcessors[procName].HasDialog(ProcessorDlg.Properties)) Then 
             _convertctrl.SelectedVideoProcessors[procName].ShowDialog(ProcessorDlg.Properties, this) 
         End If 
       Catch ex As Exception 
         MessageBox.Show(ex.Message) 
       End Try 
    End Sub 
    private void _buttonProcessor_Click(object sender, System.EventArgs e) 
    { 
       try 
       { 
         Processor deinterlace = _convertctrl.VideoProcessors.Deinterlace; 
         string procName = deinterlace.Name; 
         if (!_addedProc) 
         { 
             _convertctrl.SelectedVideoProcessors.Add(deinterlace); 
             _addedProc = true; 
         } 
         if (_convertctrl.SelectedVideoProcessors[procName].HasDialog(ProcessorDlg.Properties)) 
         { 
             _convertctrl.SelectedVideoProcessors[procName].ShowDialog(ProcessorDlg.Properties, this); 
         } 
       catch (Exception ex) 
       { 
         MessageBox.Show(this, ex.Message); 
       } 
    } 

  15. Add an event handler to the _buttonConvert Click event and code it as follows:

    C#
    VB
    Private Sub _buttonConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _buttonConvert.Click 
       Try 
           _convertctrl.Preview = True 
           _convertctrl.SourceFile = _sourceFile 
           _convertctrl.VideoCompressors.MJpeg.Selected = True 
           _convertctrl.TargetFile = _targetFile 
                            
           _convertctrl.StartConvert() 
           _buttonProcessor.Enabled = False 
           _buttonConvert.Enabled = False 
       Catch ex As Exception 
           MessageBox.Show(ex.Message) 
       End Try 
    End Sub 

    **[C#] **

    private void _buttonConvert_Click(object sender, System.EventArgs e) 
    { 
       try 
       { 
         _convertctrl.Preview = true; 
         _convertctrl.SourceFile = _sourceFile; 
         _convertctrl.VideoCompressors.MJpeg.Selected = true; 
         _convertctrl.TargetFile = _targetFile; 
                          
         _convertctrl.StartConvert(); 
         _buttonProcessor.Enabled = false; 
         _buttonConvert.Enabled = false; 
       } 
       catch (Exception ex) 
       { 
         MessageBox.Show(this, ex.Message); 
       } 
    } 

  16. Build, and Run the program to test it.

Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
Click or drag to resize