IDisplayedObjectsSetLabelText Method |
![]() |
Namespace: MediaCy.IQL.Features
Sub SetLabelText ( bstrLabelTextOrKeyword As String, Optional mcsltFlags As mcSetLabelTextFlags = mcSetLabelTextFlags.mcsltDefault, Optional lTextColor As Integer = -1, <OptionalAttribute> varIFontDisp As Object )
'Example 1: Set the label of all thresholded sub-regions in the 'ActiveImage.RegionsFeatures object to have a label showing "Idx=sub-region index". 'The label will be centered within the region and the label color will 'be set to green. The default font will be used except that it will 'be made italic and 10 point. ' With ThisApplication.ActiveImage.RegionFeatures .Threshold.Execute 'Get some regions Dim myFont As IFontDisp Set myFont = .AutoDisplayOverlay.Template("McGraphObjText").Font 'Start with default font myFont.Italic = True myFont.Size = 10 .DisplayedObjects.SetLabelText "Idx=%d", _ mcsltDisplayFeatureIndex Or mcsltLabelCenter, &HFF00&, myFont End With 'Example 2: Label regions with their area ' With ThisApplication.ActiveImage.RegionFeatures Dim varAreas As Variant varAreas = .mRgnArea Dim lF As Long For lF = 0 to .Count-1 .SourceData(lF) = CDbl(varAreas(lF)) Next lF .DisplayedObjects.SetLabelText "%.1f", _ mcsltDisplaySourceData Or mcsltLabelCenter, &HFF00&, myFont End With 'Example 3: Label regions that have holes with the number of holes ' With ThisApplication.ActiveImage.RegionFeatures .SourceFlags = .mRgnNumHoles .DisplayedObjects(McOpNE(.mRgnNumHoles,0)).SetLabelText "N holes: %d", _ mcsltDisplaySourceFlags Or mcsltLabelTopleft End With 'Example 4: Label small vs large regions ' Dim varAreas, varMeanArea varAreas = ThisApplication.ActiveImage.RegionFeatures.mRgnArea varMeanArea = McSum(varAreas) / ThisApplication.ActiveImage.RegionFeatures.mRgnArea.Count Results.Text = "There are " + Str(ActiveImage.RegionFeatures.mRgnArea.Count) + _ " regions. The mean Area is: " + McToText(varMeanArea, "%.2f") 'Get selectors for small areas and for not small (large) areas Dim selSmallAreas, selLargeAreas selSmallAreas = McOpLE(varAreas, varMeanArea) selLargeAreas = McOpNOT(selSmallAreas) Dim mdobjsSmall As IDisplayedObjects ' Set mdobjsSmall = ThisApplication.ActiveImage.RegionFeatures.DisplayedObjects(selSmallAreas, , ,mcdoAllOverlays) ' Set mdobjsSmall = ThisApplication.ActiveImage.RegionFeatures.DisplayedObjects(selSmallAreas) ' the above works just fine, below is a full equivalent call varTemplateIDList = Array(mcgtStandardAutoDisplay, mcgtDefaultTemplate) Set mdobjsSmall = ThisApplication.ActiveImage.RegionFeatures.DisplayedObjects(selSmallAreas, _ s_mcgraphoverlayToUse, varTemplateIDList) ' Now label the small regions in yellow, using the default font mdobjsSmall.SetLabelText "%d:Sm", _ mcsltDisplayFeatureIndex + mcsltLabelCenter, &HFFFF& ' Label large objects on all overlays Dim mdobjsLarge As IDisplayedObjects Set mdobjsLarge = ThisApplication.ActiveImage.RegionFeatures.DisplayedObjects(selLargeAreas, , , mcdoAllOverlays) ' Now label the Large regions with the border color, using a different font Dim imcgraphobjTemplate As IMcGraphObj Set imcgraphobjTemplate = s_mcgraphoverlayToUse.Template("McGraphObj", mcgtStandardAutoDisplay) Dim ifontdispLabel As IFontDisp Set ifontdispLabel = imcgraphobjTemplate.LabelObject.Font ifontdispLabel.Name = "Courier New" ifontdispLabel.Size = 20 ifontdispLabel.Bold = True mdobjsLarge.SetLabelText "%d:Lg", _ mcsltDisplayFeatureIndex + mcsltCopyBorderColor + mcsltLabelTopleft, -1, ifontdispLabel