VintaSoft Imaging .NET SDK 15.1: Documentation for .NET developer
Vintasoft.Imaging.UI.VisualTools Namespace / CustomSelectionTool Class
Members Object Syntax Example Hierarchy Requirements SeeAlso
In This Topic
CustomSelectionTool Class
In This Topic
Visual tool that allows to select the custom image region in an image viewer.
Object Model
SelectionRegionBase IObjectClipboard IInteractionController ImageViewer CustomSelectionTool
Syntax
Example

This C#/VB.NET code shows how to execute image processing command on the custom image region.


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);
        }
    }

}

Inheritance Hierarchy

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

Requirements

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

See Also