VintaSoft Imaging .NET SDK 15.1: Документация для .NET разработчика
Vintasoft.Imaging.UI.VisualTools Namespace / CustomSelectionTool Class
Члены типа Объект Синтаксис Example Иерархия Требования Смотрите также
В этом разделе
Класс CustomSelectionTool
В этом разделе
Визуальный инструмент, позволяющий выбрать пользовательскую область изображения в просмотрщике изображений.
Объектная модель
SelectionRegionBase IObjectClipboard IInteractionController ImageViewer CustomSelectionTool
Синтаксис
Пример

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


Class CustomSelectionToolProcessingExample
    Public Sub RunExample(viewer As Vintasoft.Imaging.UI.ImageViewer)
        ' create the CustomSelectionTool object
        Dim selectionTool As New Vintasoft.Imaging.UI.VisualTools.CustomSelectionTool()
        ' set the created tool as the current tool of the ImageViewer
        viewer.VisualTool = selectionTool
        ' set current selection to curvilinear selection
        selectionTool.Selection = New Vintasoft.Imaging.UI.VisualTools.CurvilinearSelectionRegion(New System.Drawing.PointF() {New System.Drawing.PointF(100, 100), New System.Drawing.PointF(100, 200), New System.Drawing.PointF(200, 200), New System.Drawing.PointF(200, 100)})

        ' execute blur command using selection
        ExecuteProcessing(viewer.Image, selectionTool.Selection, New Vintasoft.Imaging.ImageProcessing.Effects.MotionBlurCommand())

        ' create point-based object transformer
        Dim transformer As New Vintasoft.Imaging.UI.VisualTools.UserInteraction.PointBasedObjectPointTransformer(selectionTool.Selection)
        ' set point-based object transformer as transformer of current selection
        selectionTool.Selection.TransformInteractionController = transformer

        ' insert point to selection
        transformer.InsertPoint(New System.Drawing.PointF(150, 150), 0)

        ' translate selection points
        transformer.TranslatePoints(100, 100)

        ' execute invert command using selection
        ExecuteProcessing(viewer.Image, selectionTool.Selection, New Vintasoft.Imaging.ImageProcessing.Color.InvertCommand())

        ' clear selection
        selectionTool.Selection = Nothing
    End Sub

    ' Executes image processing command using selection region.
    Private Sub ExecuteProcessing(image As Vintasoft.Imaging.VintasoftImage, selectionRegion As Vintasoft.Imaging.UI.VisualTools.SelectionRegionBase, command As Vintasoft.Imaging.ImageProcessing.ProcessingCommandBase)
        Using path As System.Drawing.Drawing2D.GraphicsPath = selectionRegion.GetAsGraphicsPath()
            Dim processPath As New Vintasoft.Imaging.ImageProcessing.ProcessPathCommand(command, New Vintasoft.Imaging.Drawing.Gdi.GdiGraphicsPath(path, False))
            processPath.ExecuteInPlace(image)
        End Using
    End Sub

End Class


class CustomSelectionToolProcessingExample
{
    public void RunExample(Vintasoft.Imaging.UI.ImageViewer viewer)
    {
        // create the CustomSelectionTool object
        Vintasoft.Imaging.UI.VisualTools.CustomSelectionTool selectionTool = 
            new Vintasoft.Imaging.UI.VisualTools.CustomSelectionTool();
        // set the created tool as the current tool of the ImageViewer
        viewer.VisualTool = selectionTool;
        // set current selection to curvilinear selection
        selectionTool.Selection = new Vintasoft.Imaging.UI.VisualTools.CurvilinearSelectionRegion(
            new System.Drawing.PointF[] { 
            new System.Drawing.PointF(100, 100), new System.Drawing.PointF(100, 200),
            new System.Drawing.PointF(200, 200), new System.Drawing.PointF(200, 100) });

        // execute blur command using selection
        ExecuteProcessing(viewer.Image, selectionTool.Selection, 
            new Vintasoft.Imaging.ImageProcessing.Effects.MotionBlurCommand());

        // create point-based object transformer
        Vintasoft.Imaging.UI.VisualTools.UserInteraction.PointBasedObjectPointTransformer transformer =
            new Vintasoft.Imaging.UI.VisualTools.UserInteraction.PointBasedObjectPointTransformer(
                selectionTool.Selection);
        // set point-based object transformer as transformer of current selection
        selectionTool.Selection.TransformInteractionController = transformer;

        // insert point to selection
        transformer.InsertPoint(new System.Drawing.PointF(150, 150), 0);

        // translate selection points
        transformer.TranslatePoints(100, 100);

        // execute invert command using selection
        ExecuteProcessing(viewer.Image, selectionTool.Selection, 
            new Vintasoft.Imaging.ImageProcessing.Color.InvertCommand());

        // clear selection
        selectionTool.Selection = null;
    }

    // Executes image processing command using selection region.
    private void ExecuteProcessing(
        Vintasoft.Imaging.VintasoftImage image,
        Vintasoft.Imaging.UI.VisualTools.SelectionRegionBase selectionRegion,
        Vintasoft.Imaging.ImageProcessing.ProcessingCommandBase command)
    {
        using (System.Drawing.Drawing2D.GraphicsPath path = selectionRegion.GetAsGraphicsPath())
        {
            Vintasoft.Imaging.ImageProcessing.ProcessPathCommand processPath = 
                new Vintasoft.Imaging.ImageProcessing.ProcessPathCommand(command, new Vintasoft.Imaging.Drawing.Gdi.GdiGraphicsPath(path, false));
            processPath.ExecuteInPlace(image);
        }
    }

}

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

System.Object
   Vintasoft.Imaging.UI.VisualTools.VisualTool
      Vintasoft.Imaging.UI.VisualTools.UserInteraction.UserInteractionVisualTool
         Vintasoft.Imaging.UI.VisualTools.CustomSelectionTool

Требования

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

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