Scripting Resources for DigitalMicrograph™ |
Example: Adding and Removing Text Annotations to/from an Image. | |
Function |
Demonstrates how to add text annotations to an image. The font, colour and drawing mode of the annotations are also set. The annotations are then removed. |
Version |
version:20070513, v1.0 |
Author |
D. R. G. Mitchell |
Acknowledgements |
- |
Comments |
Expects the front-most image to be >512 x 512. |
System Requirements |
Should be compatible with all recent versions of DigitalMicrograph. |
Known Issues |
One problem when using text annotations is that they pick up the settings last used in DigitalMicrograph. If someone has set the text to white and you expect the annotations you are adding to be black, you may get unexpected results. It is therefore prudent to always set the font and colour before adding an annotation. |
Supported |
Yes |
Included Files |
Main script file. |
Source Code |
// Example code which shows how to add text annotations to // the front-most image, which should be 512 x 512 or greater. // These text annotations are then removed. // D. R. G. Mitchell, May 2007 // version:20070513, v1.0 // adminnospam@dmscripting.com (remove the nospam to make this email address work)
// get the front-most image
image front:=getfrontimage() component imgdisp=imagegetimagedisplay(front, 0) number i
// Add three text annotations and set their colour, display mode and font
for(i=0; i<3;i++) { component textannot=newtextannotation((100+(i*100)),400, ""+i, 16) textannot.componentsetfillmode(2) textannot.componentsetdrawingmode(1) textannot.componentsetforegroundcolor(1,1,0) textannot.componentsetbackgroundcolor(0,0,0) textannot.componentsetfontfacename("Microsoft Sans Serif") imgdisp.componentaddchildatend(textannot) } okdialog("I'm going to remove the annotations now.")
// this bit removes the annotations
number annots=imgdisp.componentcountchildrenoftype(13) result("annots = "+annots)
for (i=0; i<annots; i++) { component annotid=imgdisp.componentgetnthchildoftype(13,0) annotid.componentremovefromparent() } |