AutoSegment example for Visual Basic

Dim WithEvents RasterMrc As LEADRasterMrc
Dim RasterFxd As LEADRasterFXD

Private Sub Command1_Click()
    Set RasterMrc = New LEADRasterMrc
    Set RasterFxd = New LEADRasterFXD
    Dim RasterMrcDst As New LEADRasterMrc

   

Dim nSegID As Integer
    Set RasterMrc = New LEADRasterMrc
    Set RasterFxd = New LEADRasterFXD
    RasterMrc.BaseBackColor = RGB(200, 255, 255)
    RasterMrc.BaseForeColor = RGB(0, 80, 0)
    RasterMrc.CombineFactor = 30
    RasterMrc.CombineFlags = COMBINE_TRY
    RasterMrc.Sensitivity = 25
    RasterMrc.ImageType = IMAGETYPE_SCANNED
    RasterMrc.AutoSegment Me.ActiveForm.LEADRasterView1.Raster, 60, 60
    RasterMrc.EnumSegments
    RasterMrc.CombineFlags = COMBINE_FORCE
    RasterMrc.CombineSegments 0, 1
    RasterMrc.SaveSegmentation "C:\segments.sgm"
    RasterMrcDst.LoadSegmentation Me.ActiveForm.LEADRasterView1.Raster, "C:\segments.sgm"
    RasterMrc.StopSegmentation
    RasterMrc.StartSegmentation Me.ActiveForm.LEADRasterView1.Raster
    nSegID = RasterMrc.CreateNewSegment(Me.ActiveForm.LEADRasterView1.Raster, 10, 10, 100, 100, SEGTYPE_PICTURE)
    RasterMrc.SetSegmentData Me.ActiveForm.LEADRasterView1.Raster, nSegID, 0, 0, 10, 10, SEGTYPE_TEXT_1BIT_BW
    RasterMrcDst.StopSegmentation
    RasterMrcDst.CopySegmentationHandle RasterMrc
    RasterMrc.EnumSegments
    RasterMrc.DeleteSegment nSegID
    RasterMrcDst.StopSegmentation
    RasterMrcDst.StopSegmentation
End Sub

Private Sub RasterMrc_EnumSegments(ByVal nSegId As Long, ByVal SegmentLeft As Long, ByVal SegmentTop As Long, ByVal SegmentRight As Long, ByVal SegmentBottom As Long, ByVal SegType As LTRASTERMRCLib.MRCSegmentTypeConstants)

RasterFxd.DrawPenWidth = 2
    RasterFxd.DrawFillStyle = DRAWFILLSTYLE_TRANSPARENT
    RasterFxd.DrawMode = DRAWMODE_COPY_PEN
   
    If SegType = SEGTYPE_TEXT_1BIT_BW Then
       RasterFxd.DrawPenColor = vbBlack
    ElseIf SegType = SEGTYPE_TEXT_1BIT_COLORED Then
       RasterFxd.DrawPenColor = vbYellow
    ElseIf SegType = SEGTYPE_TEXT_2BIT_COLORED Then
       RasterFxd.DrawPenColor = vbGreen
    ElseIf SegType = SEGTYPE_GRAYSCALE_2BIT Then
       RasterFxd.DrawPenColor = vbBlue
    ElseIf SegType = SEGTYPE_GRAYSCALE_8BIT Then
       RasterFxd.DrawPenColor = vbWhite
    ElseIf SegType = SEGTYPE_PICTURE Then
       RasterFxd.DrawPenColor = vbRed
    End If
    RasterFxd.DrawRectangle Nothing, Me.ActiveForm.LEADRasterView1.GetClientDC(), SegmentLeft, SegmentTop, SegmentRight - SegmentLeft, SegmentBottom – SegmentTop
End Sub