VintaSoft Imaging .NET SDK 15.1: Документация для .NET разработчика
Vintasoft.Imaging.ImageProcessing Namespace / ParallelizingProcessingCommand Class
Класс ParallelizingProcessingCommand
В этом разделе
Команда обработки изображения, которая параллельно выполняет другую команду обработки изображения.
Объектная модель
ProcessingCommandBase RegionOfInterest ProcessingCommandResults ParallelizingProcessingCommand
Синтаксис
'Declaration

Public Class ParallelizingProcessingCommand
   Inherits ProcessingCommandWithRegion

public class ParallelizingProcessingCommand : ProcessingCommandWithRegion

Ремарки

Пользовательская команда может быть выполнена параллельно, если она переопределяет метод GetRegionOptimalDecomposition(VintasoftImage,Rectangle,Int32,Int32), а метод возвращает прямоугольники нескольких областей изображения.

Вот список стандартных команд обработки изображений, которые могут быть выполнены параллельно:


Свойство MaxThreads определяет, на скольких потоках эта команда будет параллельно выполнять другую команду.

Пример

Вот C#/VB.NET код, который демонстрирует, как параллельно размыть изображение.


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
 
*/

Иерархия наследования

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

Требования

Целевые платформы: .NET 10; .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

Смотрите также