VintaSoft Imaging .NET SDK 14.1: Documentation for .NET developer
Vintasoft.Imaging.Text Namespace / TextRegionSymbol Class / SelectionRegion Property
Syntax Example Requirements SeeAlso
In This Topic
    SelectionRegion Property (TextRegionSymbol)
    In This Topic
    Gets the selection region of this symbol, in text space.
    Syntax
    'Declaration
    
    Public ReadOnly Property SelectionRegion As Vintasoft.Imaging.RegionF
    
    
    public Vintasoft.Imaging.RegionF SelectionRegion { get; }
    
    
    public: __property Vintasoft.Imaging.RegionF* get_SelectionRegion();
    
    
    
    public:
    property Vintasoft.Imaging.RegionF^ SelectionRegion { Vintasoft.Imaging.RegionF^ get(); }
    Example

    This C#/VB.NET code shows how to draw selection region on image.

    
    ''' <summary>
    ''' Draws the selection region for text region line on specified image.
    ''' </summary>
    ''' <param name="image">An image that contains text and where selection region must be drawn.</param>
    ''' <returns>
    ''' A clone of image that contains text and with drawn selection region.
    ''' </returns>
    Public Shared Function DrawTextRegionSelection(image As Vintasoft.Imaging.VintasoftImage) As Vintasoft.Imaging.VintasoftImage
        ' create result image
        Dim result As Vintasoft.Imaging.VintasoftImage = DirectCast(image.Clone(), Vintasoft.Imaging.VintasoftImage)
    
        ' get the text region lines
        Dim textRegionLines As Vintasoft.Imaging.Text.TextRegionLine() = image.Metadata.TextRegion.Lines
    
        ' if image has text regions
        If textRegionLines.Length > 0 Then
            ' create the drawing engine
            Using darawingEngine As Vintasoft.Imaging.Drawing.DrawingEngine = result.CreateDrawingEngine()
                ' create transform from text to an image space
                Dim textToImageTransform As Vintasoft.Imaging.AffineMatrix = image.Metadata.TextRegion.GetTransformFromTextToImageSpace(image.Resolution)
    
                ' create brushes
                Using lineBrush As Vintasoft.Imaging.Drawing.IDrawingBrush = darawingEngine.DrawingFactory.CreateSolidBrush(New Vintasoft.Imaging.ImageColors.Argb32Color(128, 0, 128, 0))
                    Using symbolPen As Vintasoft.Imaging.Drawing.IDrawingPen = darawingEngine.DrawingFactory.CreatePen(New Vintasoft.Imaging.ImageColors.Argb32Color(255, 0, 0, 255), 1)
                        For Each textRegionLine As Vintasoft.Imaging.Text.TextRegionLine In textRegionLines
                            ' get points of text region line
                            Dim linePoints As System.Drawing.PointF() = textRegionLine.SelectionRegion.ToPolygon()
    
                            ' transform points
                            Vintasoft.Imaging.PointFAffineTransform.TransformPoints(textToImageTransform, linePoints)
    
                            ' fill line polygon
                            darawingEngine.FillPolygon(lineBrush, linePoints)
    
                            ' for each symbol in text region line
                            For Each textRegionSymbol As Vintasoft.Imaging.Text.TextRegionSymbol In textRegionLine.Symbols
                                ' get points of text symbol
                                Dim symbolPoints As System.Drawing.PointF() = textRegionSymbol.SelectionRegion.ToPolygon()
    
                                ' transform points
                                Vintasoft.Imaging.PointFAffineTransform.TransformPoints(textToImageTransform, symbolPoints)
    
                                ' fill symbol polygon
                                darawingEngine.DrawPolygon(symbolPen, symbolPoints)
                            Next
                        Next
                    End Using
                End Using
            End Using
        End If
    
        Return result
    End Function
    
    
    
    /// <summary>
    /// Draws the selection region for text region line on specified image.
    /// </summary>
    /// <param name="image">An image that contains text and where selection region must be drawn.</param>
    /// <returns>
    /// A clone of image that contains text and with drawn selection region.
    /// </returns>
    public static Vintasoft.Imaging.VintasoftImage DrawTextRegionSelection(Vintasoft.Imaging.VintasoftImage image)
    {
        // create result image
        Vintasoft.Imaging.VintasoftImage result = (Vintasoft.Imaging.VintasoftImage)image.Clone();
    
        // get the text region lines
        Vintasoft.Imaging.Text.TextRegionLine[] textRegionLines = image.Metadata.TextRegion.Lines;
    
        // if image has text regions
        if (textRegionLines.Length > 0)
        {
            // create the drawing engine
            using (Vintasoft.Imaging.Drawing.DrawingEngine darawingEngine = result.CreateDrawingEngine())
            {
                // create transform from text to an image space
                Vintasoft.Imaging.AffineMatrix textToImageTransform = image.Metadata.TextRegion.GetTransformFromTextToImageSpace(image.Resolution);
    
                // create brushes
                using (Vintasoft.Imaging.Drawing.IDrawingBrush lineBrush = darawingEngine.DrawingFactory.CreateSolidBrush(new Vintasoft.Imaging.ImageColors.Argb32Color(128, 0, 128, 0)))
                {
                    using (Vintasoft.Imaging.Drawing.IDrawingPen symbolPen = darawingEngine.DrawingFactory.CreatePen(new Vintasoft.Imaging.ImageColors.Argb32Color(255, 0, 0, 255), 1))
                    {
                        foreach (Vintasoft.Imaging.Text.TextRegionLine textRegionLine in textRegionLines)
                        {
                            // get points of text region line
                            System.Drawing.PointF[] linePoints = textRegionLine.SelectionRegion.ToPolygon();
    
                            // transform points
                            Vintasoft.Imaging.PointFAffineTransform.TransformPoints(textToImageTransform, linePoints);
    
                            // fill line polygon
                            darawingEngine.FillPolygon(lineBrush, linePoints);
    
                            // for each symbol in text region line
                            foreach (Vintasoft.Imaging.Text.TextRegionSymbol textRegionSymbol in textRegionLine.Symbols)
                            {
                                // get points of text symbol
                                System.Drawing.PointF[] symbolPoints = textRegionSymbol.SelectionRegion.ToPolygon();
    
                                // transform points
                                Vintasoft.Imaging.PointFAffineTransform.TransformPoints(textToImageTransform, symbolPoints);
    
                                // fill symbol polygon
                                darawingEngine.DrawPolygon(symbolPen, symbolPoints);
                            }
                        }
                    }
                }
            }
        }
    
        return result;
    }
    
    

    Requirements

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

    See Also