VintaSoft Imaging .NET SDK 12.4: Documentation for .NET developer
Vintasoft.Imaging.ImageProcessing Namespace / ParallelizingProcessingCommand Class
Members Object Syntax Remarks Example Hierarchy Requirements SeeAlso
In This Topic
    ParallelizingProcessingCommand Class
    In This Topic
    Image processing command that executes another image processing command parallely.
    Object Model
    ProcessingCommandBase RegionOfInterest ProcessingCommandResults ParallelizingProcessingCommand
    Syntax
    'Declaration
    
    Public Class ParallelizingProcessingCommand
       Inherits ProcessingCommandWithRegion
    
    
    public class ParallelizingProcessingCommand : ProcessingCommandWithRegion
    
    
    public __gc class ParallelizingProcessingCommand : public ProcessingCommandWithRegion*
    
    
    public ref class ParallelizingProcessingCommand : public ProcessingCommandWithRegion^
    
    
    Remarks
    Example

    This C#/VB.NET code shows how to blur image parallely.

    
    Public Shared Sub Test()
        ' create image
        Using image As New Vintasoft.Imaging.VintasoftImage(3000, 3000)
            ' add noise to an image
            Dim addNoize As New Vintasoft.Imaging.ImageProcessing.Filters.AddNoiseCommand()
            addNoize.ExecuteInPlace(image)
    
            ' blur image - this call prevents the wrong results of next calls
            Dim command As Vintasoft.Imaging.ImageProcessing.ProcessingCommandBase = New Vintasoft.Imaging.ImageProcessing.Filters.BlurCommand(11)
            Using processedImage As Vintasoft.Imaging.VintasoftImage = command.Execute(image)
            End Using
    
            System.Console.WriteLine("Multithread tests of {0} command:", command)
            For maxThreads As Integer = 1 To System.Environment.ProcessorCount
                ' blur image and output an execution time in milliseconds
    
                Dim dt As System.DateTime = System.DateTime.Now
                Using processedImage As Vintasoft.Imaging.VintasoftImage = ExecuteProcessingCommand(command, maxThreads, image)
                End Using
                Dim milliseconds As Integer = CInt((System.DateTime.Now - dt).TotalMilliseconds)
                System.Console.WriteLine("{0} thread(s): {1} ms", maxThreads, milliseconds)
            Next
        End Using
    End Sub
    
    ''' <summary>
    ''' Executes a processing command on specific number of threads.
    ''' </summary>
    Private Shared Function ExecuteProcessingCommand(command As Vintasoft.Imaging.ImageProcessing.ProcessingCommandBase, maxThreadsCount As Integer, image As Vintasoft.Imaging.VintasoftImage) As Vintasoft.Imaging.VintasoftImage
        If maxThreadsCount = 1 Then
            Return command.Execute(image)
        End If
    
        Dim parallelizingCommand As New Vintasoft.Imaging.ImageProcessing.ParallelizingProcessingCommand(command)
        parallelizingCommand.MaxThreads = maxThreadsCount
        Return parallelizingCommand.Execute(image)
    End Function
    
    ' This code example produces the following output:
        
       Multithread tests of Blur command:
       1 thread(s): 6262 ms
       2 thread(s): 3455 ms
       3 thread(s): 3169 ms
       4 thread(s): 3079 ms
       
      
    
    
    
    
    public static void Test()
    {
        // create image
        using (Vintasoft.Imaging.VintasoftImage image =
            new Vintasoft.Imaging.VintasoftImage(3000, 3000))
        {
            // add noise to an image
            Vintasoft.Imaging.ImageProcessing.Filters.AddNoiseCommand addNoize =
                new Vintasoft.Imaging.ImageProcessing.Filters.AddNoiseCommand();
            addNoize.ExecuteInPlace(image);
    
            // blur image - this call prevents the wrong results of next calls
            Vintasoft.Imaging.ImageProcessing.ProcessingCommandBase command =
                new Vintasoft.Imaging.ImageProcessing.Filters.BlurCommand(11);
            using (Vintasoft.Imaging.VintasoftImage processedImage =
                command.Execute(image))
            {
            }
    
            System.Console.WriteLine("Multithread tests of {0} command:", command);
            for (int maxThreads = 1; maxThreads <= System.Environment.ProcessorCount; maxThreads++)
            {
                // blur image and output an execution time in milliseconds
    
                System.DateTime dt = System.DateTime.Now;
                using (Vintasoft.Imaging.VintasoftImage processedImage =
                    ExecuteProcessingCommand(command, maxThreads, image))
                {
                }
                int milliseconds = (int)(System.DateTime.Now - dt).TotalMilliseconds;
                System.Console.WriteLine("{0} thread(s): {1} ms", maxThreads, milliseconds);
            }
        }
    }
    
    /// <summary>
    /// Executes a processing command on specific number of threads.
    /// </summary>
    private static Vintasoft.Imaging.VintasoftImage ExecuteProcessingCommand(
        Vintasoft.Imaging.ImageProcessing.ProcessingCommandBase command,
        int maxThreadsCount,
        Vintasoft.Imaging.VintasoftImage image)
    {
        if (maxThreadsCount == 1)
            return command.Execute(image);
    
        Vintasoft.Imaging.ImageProcessing.ParallelizingProcessingCommand parallelizingCommand =
            new Vintasoft.Imaging.ImageProcessing.ParallelizingProcessingCommand(command);
        parallelizingCommand.MaxThreads = maxThreadsCount;
        return parallelizingCommand.Execute(image);
    }
    
    /* This code example produces the following output:
      
     Multithread tests of Blur command:
     1 thread(s): 6262 ms
     2 thread(s): 3455 ms
     3 thread(s): 3169 ms
     4 thread(s): 3079 ms
     
    */
    
    

    Inheritance Hierarchy

    System.Object
       Vintasoft.Imaging.ImageProcessing.ProcessingCommandBase
          Vintasoft.Imaging.ImageProcessing.ProcessingCommandWithRegion
             Vintasoft.Imaging.ImageProcessing.ParallelizingProcessingCommand

    Requirements

    Target Platforms: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    See Also