Leadtools.Windows.Annotations Requires Document/Medical license. | Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
SaveToTag Method
See Also  Example
Leadtools.Windows.Annotations Namespace > AnnCodecs Class : SaveToTag Method



container
The AnnContainer containing the objects to be saved.
format
An AnnCodecsTagFormat value that specifies the format used when creating the tag data.
container
The AnnContainer containing the objects to be saved.
format
An AnnCodecsTagFormat value that specifies the format used when creating the tag data.
Saves the annotation objects in a container as a TIFF tag data.

Syntax

Visual Basic (Declaration) 
Public Function SaveToTag( _
   ByVal container As AnnContainer, _
   ByVal format As AnnCodecsTagFormat _
) As Byte()
Visual Basic (Usage)Copy Code
Dim instance As AnnCodecs
Dim container As AnnContainer
Dim format As AnnCodecsTagFormat
Dim value() As Byte
 
value = instance.SaveToTag(container, format)
C# 
public byte[] SaveToTag( 
   AnnContainer container,
   AnnCodecsTagFormat format
)
C++/CLI 
public:
array<byte>^ SaveToTag( 
   AnnContainer^ container,
   AnnCodecsTagFormat format
) 

Parameters

container
The AnnContainer containing the objects to be saved.
format
An AnnCodecsTagFormat value that specifies the format used when creating the tag data.

Return Value

A byte array that can be saved into a TIFF file using SetQuery method.

Example

Visual BasicCopy Code
Public Sub AnnCodecs_SaveToTag(ByVal viewer As BitmapSourceViewer, ByVal tifFileName As String)
  ' first create a container and add a few objects
  Dim container As AnnContainer = New AnnContainer()
  container.Width = 400
  container.Height = 400
  Dim lineObj As AnnLineObject = New AnnLineObject()
  lineObj.X1 = 100
  lineObj.Y1 = 100
  lineObj.X2 = 200
  lineObj.Y2 = 200
  lineObj.Stroke = Brushes.Red
  lineObj.StrokeThickness = 1.0
  container.Children.Add(lineObj)

  Dim rectObj As AnnRectangleObject = New AnnRectangleObject()
  rectObj.Left = 100
  rectObj.Top = 100
  rectObj.Width = 200
  rectObj.Height = 200
  rectObj.Stroke = Brushes.Red
  rectObj.StrokeThickness = 1.0
  rectObj.Fill = Brushes.White
  container.Children.Add(rectObj)

  ' create a new instance of the AnnCodecs object
  Dim ann As AnnCodecs = New AnnCodecs()

  ' save this container as a TIFF tag
  Dim tagData As Byte() = ann.SaveToTag(container, AnnCodecsTagFormat.Serialize)

  If Not tagData Is Nothing Then
       Dim fs1 As FileStream = New FileStream(tifFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)
    Dim bmd As BitmapMetadata = New BitmapMetadata("tiff")
    bmd.SetQuery("/ifd/{uint=32932}", tagData)
       Dim bf1 As BitmapFrame = BitmapFrame.Create(viewer.Source, Nothing, bmd, Nothing)

    Dim tiffEncoder As TiffBitmapEncoder = New TiffBitmapEncoder()
       tiffEncoder.Frames.Add(bf1)
       tiffEncoder.Save(fs1)

       fs1.Close()
  End If

  ' clear the container and the tag
  container.Children.Clear()
  tagData = Nothing

  ' re-load the tag
    Dim fs As FileStream = New FileStream(tifFileName, FileMode.Open)
    Dim bf As BitmapFrame = BitmapFrame.Create(fs)
    Dim tiffInplace As InPlaceBitmapMetadataWriter = Nothing
    Try
       tiffInplace = bf.CreateInPlaceBitmapMetadataWriter()
    Catch
    Finally
       If Not tiffInplace Is Nothing AndAlso tiffInplace.ContainsQuery("/ifd/{uint=32932}") Then
         tagData = CType(tiffInplace.GetQuery("/ifd/{uint=32932}"), Byte())
       End If
       fs.Close()
    End Try

  ' load the container
  ann.LoadFromTag(tagData, container)
End Sub
C#Copy Code
public void AnnCodecs_SaveToTag(BitmapSourceViewer viewer, string tifFileName) 

   // first create a container and add a few objects 
   AnnContainer container = new AnnContainer(); 
   container.Width = 400; 
   container.Height = 400; 
   AnnLineObject lineObj = new AnnLineObject(); 
   lineObj.X1 = 100; 
   lineObj.Y1 = 100; 
   lineObj.X2 = 200; 
   lineObj.Y2 = 200; 
   lineObj.Stroke = Brushes.Red; 
   lineObj.StrokeThickness = 1.0; 
   container.Children.Add(lineObj); 
 
   AnnRectangleObject rectObj = new AnnRectangleObject(); 
   rectObj.Left = 100; 
   rectObj.Top = 100; 
   rectObj.Width = 200; 
   rectObj.Height = 200; 
   rectObj.Stroke = Brushes.Red; 
   rectObj.StrokeThickness = 1.0; 
   rectObj.Fill = Brushes.White; 
   container.Children.Add(rectObj); 
 
   // create a new instance of the AnnCodecs object 
   AnnCodecs ann = new AnnCodecs(); 
 
   // save this container as a TIFF tag 
   byte[] tagData = ann.SaveToTag(container, AnnCodecsTagFormat.Serialize); 
 
   if(tagData != null) 
   { 
      FileStream fs = new FileStream(tifFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); 
      BitmapMetadata bmd = new BitmapMetadata("tiff"); 
      bmd.SetQuery("/ifd/{uint=32932}", tagData); 
      BitmapFrame bf = BitmapFrame.Create(viewer.Source, null, bmd, null); 
 
      TiffBitmapEncoder tiffEncoder = new TiffBitmapEncoder(); 
      tiffEncoder.Frames.Add(bf); 
      tiffEncoder.Save(fs); 
 
      fs.Close(); 
   } 
 
   // clear the container and the tag 
   container.Children.Clear(); 
   tagData = null; 
 
   // re-load the tag 
   { 
      FileStream fs = new FileStream(tifFileName, FileMode.Open); 
      BitmapFrame bf = BitmapFrame.Create(fs); 
      InPlaceBitmapMetadataWriter tiffInplace = null; 
      try 
      { 
         tiffInplace = bf.CreateInPlaceBitmapMetadataWriter(); 
      } 
      catch 
      { 
      } 
      finally 
      { 
         if(tiffInplace != null && tiffInplace.ContainsQuery("/ifd/{uint=32932}")) 
         { 
            tagData = (byte[])tiffInplace.GetQuery("/ifd/{uint=32932}"); 
         } 
         fs.Close(); 
      } 
   } 
 
   // load the container 
   ann.LoadFromTag(tagData, container); 
}

Remarks

This method will return byte array that can be saved to Tiff file using SetQuery method passing the query '/ifd/{uint=32932}'.

This method can return null (Nothing in Visual Basic) if you try to save unsupported objects to certain formats (for example, if you try to save an AnnRubberStampObject to a Wang format).

For more information, refer to WPF Annotation Files.

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Vista, and Windows Server 2003 family

See Also

SaveToTag requires a Document/Medical product license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features and Unlocking Special LEAD Features.