AutoSegment Example for C++ 5.0 and later

void CT44Dlg::OnAutoSeg()
{
   //Instantiate the sink class and hold a pointer to it.
   m_pRasterMrcSink = new CRasterMrcSink;
   m_pRasterMrcSink->m_pView = this;

ILEADRasterMrc* pRasterMrc;
   ILEADRasterMrc* pRasterMrcDst;
   int nSegID;
   //Create the RasterMrc object
   CoCreateInstance(CLSID_LEADRasterMrc, NULL, CLSCTX_ALL, IID_ILEADRasterMrc, (void**)&pRasterMrc);
   CoCreateInstance(CLSID_LEADRasterMrc, NULL, CLSCTX_ALL, IID_ILEADRasterMrc, (void**)&pRasterMrcDst);
   
   pRasterMrc->BaseBackColor = RGB(200, 255, 255);
   pRasterMrc->BaseForeColor = RGB(0, 80, 0);
   pRasterMrc->CombineFactor = 30;
   pRasterMrc->CombineFlags = COMBINE_TRY;
   pRasterMrc->Sensitivity = 25;
   pRasterMrc->ImageType = IMAGETYPE_SCANNED;
   pRasterMrc->AutoSegment(m_RasterView.GetRaster(), 60, 60);
   pRasterMrc->EnumSegments();
   pRasterMrc->CombineFlags = COMBINE_FORCE;
   pRasterMrc->CombineSegments(0, 1);
   pRasterMrc->SaveSegmentation("C:\\segments.sgm");
   pRasterMrcDst->LoadSegmentation(m_RasterView.GetRaster(), "C:\\segments.sgm");
   pRasterMrc->StopSegmentation();
   pRasterMrc->StartSegmentation(m_RasterView.GetRaster());
   nSegID = pRasterMrc->CreateNewSegment(m_RasterView.GetRaster(), 10, 10, 100, 100, SEGTYPE_PICTURE);
   pRasterMrc->SetSegmentData(m_RasterView.GetRaster(), nSegID, 0, 0, 10, 10, SEGTYPE_TEXT_1BIT_BW);
   pRasterMrcDst->StopSegmentation();
   pRasterMrcDst->CopySegmentationHandle(pRasterMrc);
   pRasterMrc->EnumSegments();
   pRasterMrc->DeleteSegment(nSegID);
   pRasterMrcDst->StopSegmentation();
   pRasterMrcDst->StopSegmentation();
   pRasterMrc->Release();
   pRasterMrc = NULL;
   pRasterMrcDst->Release();
   pRasterMrcDst = NULL;
}
void CRasterMrcSink:: EnumSegments(long nSegId, long SegmentLeft, long SegmentTop,
                                  long SegmentRight, long SegmentBottom,
                                  MRCSegmentTypeConstants SegType)
{
  ILEADRasterFXD *pRasterFXD=NULL;
   CoCreateInstance(CLSID_LEADRasterFXD, NULL, CLSCTX_ALL, IID_ILEADRasterFXD, (void**)&pRasterFXD);

   pRasterFXD->put_DrawPenWidth(2);
   pRasterFXD->put_DrawFillStyle(DRAWFILLSTYLE_TRANSPARENT);
   pRasterFXD->put_DrawMode(DRAWMODE_COPY_PEN);
   
   if (SegType == SEGTYPE_TEXT_1BIT_BW)
      pRasterFXD->put_DrawPenColor(0);
   else if (SegType == SEGTYPE_TEXT_1BIT_COLORED)
      pRasterFXD->put_DrawPenColor(RGB(255, 225, 0));
   else if (SegType == SEGTYPE_TEXT_2BIT_COLORED)
      pRasterFXD->put_DrawPenColor(RGB(0, 255, 0));
   else if (SegType == SEGTYPE_GRAYSCALE_2BIT)
      pRasterFXD->put_DrawPenColor(RGB(0, 0, 255));
   else if (SegType == SEGTYPE_GRAYSCALE_8BIT)
      pRasterFXD->put_DrawPenColor(RGB(255, 255, 255));
   else if (SegType == SEGTYPE_PICTURE)
      pRasterFXD->put_DrawPenColor(RGB(255, 0, 0));
   
   pRasterFXD->DrawRectangle(NULL, m_pView->m_RasterView.GetClientDC(), SegmentLeft, SegmentTop, SegmentRight - SegmentLeft, SegmentBottom - SegmentTop);
   
   pRasterFXD->Release();
}