Creating DICOM Annotations Example for C#

private void CreateAnnotations(ref LTDICLib.LEADDicomDS objPresStateDS)
{
   // Set the attributes that describe the "Presentation State Module"
   objPresStateDS.PresStateAttributes.InstanceNumber = 1;
   objPresStateDS.PresStateAttributes.PresLabel = "SOME_LABEL";
   objPresStateDS.PresStateAttributes.PresDescription = "Description of the presentation";
   objPresStateDS.PresStateAttributes.PresCreationDate.Year = (short)System.DateTime.Today.Year;
   objPresStateDS.PresStateAttributes.PresCreationDate.Month = (short)System.DateTime.Today.Month;
   objPresStateDS.PresStateAttributes.PresCreationDate.Day = (short)System.DateTime.Today.Day;
   objPresStateDS.PresStateAttributes.PresCreationTime.Hours = (short)System.DateTime.Today.Hour;
   objPresStateDS.PresStateAttributes.PresCreationTime.Minutes = (short)System.DateTime.Today.Minute;
   objPresStateDS.PresStateAttributes.PresCreationTime.Seconds = (short)System.DateTime.Today.Second;
   objPresStateDS.PresStateAttributes.PresCreationTime.Fractions = 0;
   objPresStateDS.PresStateAttributes.PresCreatorName = "SomeOne";
   if (objPresStateDS.SetPresStateAttributes() == (short)LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS)
      MessageBox.Show("Presentation State attributes were set successfully.");

   // Add references to some images (under the "Presentation State Module")
   objPresStateDS.AddPresStateImageRef ("C:\\Image1.dic", null);
   objPresStateDS.AddPresStateImageRef ("C:\\Image2.dic", null);
   objPresStateDS.AddPresStateImageRef ("C:\\Image3.dic", null);
   string sLayerName= null;

   // Create a layer
   objPresStateDS.LayerAttributes.LayerName = "LAYER_0";

   // "Graphic Layer"
   objPresStateDS.LayerAttributes.LayerOrder = 1;
   objPresStateDS.LayerAttributes.DisplayGrayscaleValue = -1;
   objPresStateDS.LayerAttributes.DisplayRedValue = -1;
   objPresStateDS.LayerAttributes.DisplayGreenValue = -1;
   objPresStateDS.LayerAttributes.DisplayRedValue = -1;
   objPresStateDS.LayerAttributes.LayerDescription = "Description of the layer";
   if (objPresStateDS.CreateLayer() == (short)LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS)
   {
      sLayerName= objPresStateDS.LayerAttributes.LayerName;
      MessageBox.Show("Layer '" + sLayerName+ "' was created successfully.");
      // Change one of the attributes and update the layer
      objPresStateDS.LayerAttributes.LayerOrder = 0;
      objPresStateDS.SetLayerAttributes(objPresStateDS.NewLayerIndex);
   }
   int hGraphicAnnItem = 0;
   // Create a Graphic Annotation Item
   if (objPresStateDS.CreateGraphicAnnItem(0, sLayerName) == (short)LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS)
   {
      MessageBox.Show("A Graphic Annotation Item was created successfully.");
      objPresStateDS.FindFirstGraphicAnnItem();
      hGraphicAnnItem = objPresStateDS.get_CurrentElement().hElement;
   }
   string sSOPInstanceUID = null;
   // The annotations defined in the Item hGraphicAnnItem will be applied
   // only to one of the images listed in the Presentation State Module
   if (objPresStateDS.FindFirstPresStateRefSeriesItem() == (short)LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS)
   {
      if (objPresStateDS.GetPresStateImageRefCount() > 0)
          sSOPInstanceUID = objPresStateDS.GetPresStateImageRefInstanceUID(0);
   }
   objPresStateDS.SetCurrentElement(hGraphicAnnItem);
   objPresStateDS.AddLayerImageRef(sSOPInstanceUID);
   // Let's create a graphic annotation object
   objPresStateDS.GraphicObjectAttributes.LayerName= sLayerName;
   objPresStateDS.GraphicObjectAttributes.Units = LTDICLib.DicomMeasureUnits.DICOM_UNIT_PIXEL;
   objPresStateDS.GraphicObjectAttributes.Type = LTDICLib.DicomGraphicObjectTypes.DICOM_GRAPHIC_OBJECT_TYPE_CIRCLE;
   objPresStateDS.GraphicObjectAttributes.Filled = true;
   objPresStateDS.GraphicObjectAttributes.PointCount = 2;
   // "Number of Graphic Points"
   // "Graphic Data":
   objPresStateDS.GraphicObjectAttributes.set_PointsX(0, 252.5F);
   objPresStateDS.GraphicObjectAttributes.set_PointsY(0, 252.5F);
   objPresStateDS.GraphicObjectAttributes.set_PointsX(1, 209.2F);
   objPresStateDS.GraphicObjectAttributes.set_PointsY(1, 199.6F);
   if (objPresStateDS.CreateGraphicObject(true) == (short)LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS)
   {
      MessageBox.Show("A graphic annotation object was created successfully.");
      // Change one of the attributes and update the object
      objPresStateDS.GraphicObjectAttributes.Filled = false;
      objPresStateDS.SetGraphicObjectAttributes(0);
   }

   // Let's now create a text annotation object
   objPresStateDS.TextObjectAttributes.LayerName= sLayerName;
   objPresStateDS.TextObjectAttributes.BoundingBoxUsed = true;
   objPresStateDS.TextObjectAttributes.AnchorPointUsed = false;
   objPresStateDS.TextObjectAttributes.BoundingBoxUnits = LTDICLib.DicomMeasureUnits.DICOM_UNIT_PIXEL;
   objPresStateDS.TextObjectAttributes.TextValue = "Text annotation (using a bounding box)";
   objPresStateDS.TextObjectAttributes.BoundingBoxTLHCornerX = 176.7F;
   objPresStateDS.TextObjectAttributes.BoundingBoxTLHCornerY = 117.7F;
   objPresStateDS.TextObjectAttributes.BoundingBoxBRHCornerX = 320.3F;
   objPresStateDS.TextObjectAttributes.BoundingBoxBRHCornerY = 136.1F;
   objPresStateDS.TextObjectAttributes.BoundingBoxTextJustification = LTDICLib.DicomTextJustificationTypes.DICOM_TEXT_JUSTIFICATION_RIGHT;
   if (objPresStateDS.CreateTextObject(true) == (short)LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS)
   {
      MessageBox.Show("A text annotation object was created successfully.");
      // Change one of the attributes and update the object
      objPresStateDS.TextObjectAttributes.BoundingBoxTextJustification = LTDICLib.DicomTextJustificationTypes.DICOM_TEXT_JUSTIFICATION_LEFT;
      objPresStateDS.SetTextObjectAttributes(0);
   }
   // And another text annotation object
   objPresStateDS.TextObjectAttributes.LayerName= sLayerName;
   objPresStateDS.TextObjectAttributes.AnchorPointUsed = true;
   objPresStateDS.TextObjectAttributes.BoundingBoxUsed = false;
   objPresStateDS.TextObjectAttributes.AnchorPointUnits = LTDICLib.DicomMeasureUnits.DICOM_UNIT_PIXEL;
   objPresStateDS.TextObjectAttributes.TextValue = "Text annotation (using an anchor point)";
   objPresStateDS.TextObjectAttributes.AnchorPointX = 277.9F;
   objPresStateDS.TextObjectAttributes.AnchorPointY = 382.7F;
   objPresStateDS.TextObjectAttributes.AnchorPointVisible = true;
   if (objPresStateDS.CreateTextObject(true) == (short)LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS)
       MessageBox.Show("Another text annotation object was created successfully.");
   }