AutoSegment Example for C++ Builder

void __fastcall TForm1::Button1Click(TObject *Sender)
{
   int nSegID;

   LEADMrc1->BaseBackColor = RGB(200, 255, 255);
   LEADMrc1->BaseForeColor = RGB(0, 80, 0);
   LEADMrc1->CombineFactor = 20;
   LEADMrc1->CombineFlags = COMBINE_TRY;
   LEADMrc1->Sensitivity = 25;
   LEADMrc1->ImageType = IMAGETYPE_SCANNED;
   LEADMrc1->AutoSegment(LEADImage1, 60, 60);
   LEADMrc1->EnumSegments();
   LEADMrc1->CombineFlags = COMBINE_FORCE;
   LEADMrc1->CombineSegments(0, 1);
   LEADMrc1->SaveSegmentation("C:\\segments.sgm");
   LEADMrcDst->LoadSegmentation(LEADImage1, "C:\\segments.sgm");
   LEADMrc1->StopSegmentation();
   LEADMrc1->StartSegmentation(LEADImage1);
   nSegID = LEADMrc1->CreateNewSegment(LEADImage1, 10, 10, 100, 100, SEGTYPE_PICTURE);
   LEADMrc1->SetSegmentData(LEADImage1, nSegID, 0, 0, 10, 10, SEGTYPE_TEXT_1BIT_BW);
   LEADMrcDst->StopSegmentation();
   LEADMrcDst->CopySegmentationData(LEADMrc1);
   LEADMrc1->EnumSegments();
   LEADMrc1->DeleteSegment(nSegID);
   LEADMrcDst->StopSegmentation();
   LEADMrc1->StopSegmentation();
}


void __fastcall TForm1::LEADMrc1EnumSegments(int SegmentID, int SegmentLeft, int SegmentTop, int SegmentRight, int SegmentBottom, DWORD SegmentType)
{
   LEADImage1-> DrawPenWidth= 2;
   LEADImage1-> DrawFillStyle= bsClear;
   LEADImage1-> DrawMode= pmCopy;

   if(SegmentType == SEGTYPE_TEXT_1BIT_BW)
      LEADImage1-> DrawPenColor= clBlack;
   else if(SegmentType == SEGTYPE_TEXT_1BIT_COLOR)
      LEADImage1->DrawPenColor= clYellow;
   else if(SegmentType == SEGTYPE_TEXT_2BIT_COLOR)
      LEADImage1->DrawPenColor= clGreen;
   else if(SegmentType == SEGTYPE_GRAYSCALE_2BIT)
      LEADImage1->DrawPenColor= clBlue;
   else if(SegmentType == SEGTYPE_GRAYSCALE_8BIT)
      LEADImage1->DrawPenColor= clWhite;
   else if(SegmentType == SEGTYPE_PICTURE)
      LEADImage1->DrawPenColor= clRed;;

   LEADImage1->DrawRectangle(SegmentLeft, SegmentTop, SegmentRight - SegmentLeft, SegmentBottom - SegmentTop);
}