LEADTOOLS Annotations for WPF and Silverlight (Leadtools.Windows.Annotations assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.31
Save(Stream,AnnContainer) Method
See Also 
Leadtools.Windows.Annotations Namespace > AnnCodecs Class > Save Method : Save(Stream,AnnContainer) Method



stream
The stream to which to save the objects.
container
An AnnContainer containing the objects to be saved.

The Save(Stream,AnnContainer) Method supports WPF/Silverlight.

The Save(Stream,AnnContainer) Method is available in LEADTOOLS Document and Medical Imaging toolkits.

stream
The stream to which to save the objects.
container
An AnnContainer containing the objects to be saved.
Saves the annotation objects to a stream. Supported in Silverlight, Windows Phone 7

Syntax

Visual Basic (Declaration) 
Overloads Public Shared Sub Save( _
   ByVal stream As Stream, _
   ByVal container As AnnContainer _
) 
Visual Basic (Usage)Copy Code
Dim stream As Stream
Dim container As AnnContainer
 
AnnCodecs.Save(stream, container)
C# 
public static void Save( 
   Stream stream,
   AnnContainer container
)
C++/CLI 
public:
static void Save( 
   Stream^ stream,
   AnnContainer^ container
) 

Parameters

stream
The stream to which to save the objects.
container
An AnnContainer containing the objects to be saved.

Example

Visual BasicCopy Code
Public Sub AnnCodecs_LoadSaveContainer()
   ' create a new annotation container
   Dim container As New AnnContainer()
   ' add a few objects into the container

   Dim rectObj As New AnnRectangleObject()
   rectObj.Rect = New Rect(100, 100, 100, 100)
   rectObj.Stroke = Colors.Blue
   rectObj.Fill = Colors.Transparent
   rectObj.StrokeThickness = 1.0
   container.Children.Add(rectObj)

   Dim lineObj As New AnnLineObject()
   lineObj.Start = New Point(100, 100)
   lineObj.End = New Point(200, 200)
   lineObj.Stroke = Colors.Red
   lineObj.StrokeThickness = 1.0
   container.Children.Add(lineObj)

   MessageBox.Show(String.Format("Before Save: Container has {0} objects", container.Children.Count))

   ' create a memory stream to save the objects into
   Using ms As New MemoryStream()
      ' save the objects in this container
      AnnCodecs.Save(ms, container)
      ms.Position = 0

      ' clear the container
      container.Children.Clear()
      MessageBox.Show(String.Format("After Save and Clear: Container has {0} objects, Stream size: {1}", container.Children.Count, ms.Length))


      ' load the objects back from the stream
      AnnCodecs.Load(ms, container)

      MessageBox.Show(String.Format("After Load: Container has {0} objects", container.Children.Count))
   End Using
End Sub
C#Copy Code
public void AnnCodecs_LoadSaveContainer()
{
   // create a new annotation container
   AnnContainer container = new AnnContainer();
   // add a few objects into the container

   AnnRectangleObject rectObj = new AnnRectangleObject();
   rectObj.Rect = new Rect(100, 100, 100, 100);
   rectObj.Stroke = Colors.Blue;
   rectObj.Fill = Colors.Transparent;
   rectObj.StrokeThickness = 1.0;
   container.Children.Add(rectObj);

   AnnLineObject lineObj = new AnnLineObject();
   lineObj.Start = new Point(100, 100);
   lineObj.End = new Point(200, 200);
   lineObj.Stroke = Colors.Red;
   lineObj.StrokeThickness = 1.0;
   container.Children.Add(lineObj);

   MessageBox.Show(string.Format("Before Save: Container has {0} objects", container.Children.Count));

   // create a memory stream to save the objects into
   using(MemoryStream ms = new MemoryStream())
   {
      // save the objects in this container
      AnnCodecs.Save(ms, container);
      ms.Position = 0;

      // clear the container
      container.Children.Clear();
      MessageBox.Show(string.Format("After Save and Clear: Container has {0} objects, Stream size: {1}", container.Children.Count, ms.Length));


      // load the objects back from the stream
      AnnCodecs.Load(ms, container);

      MessageBox.Show(String.Format("After Load: Container has {0} objects", container.Children.Count));
   }
}
SilverlightCSharpCopy Code
public void AnnCodecs_LoadSaveContainer()
{
   // create a new annotation container
   AnnContainer container = new AnnContainer();
   // add a few objects into the container

   AnnRectangleObject rectObj = new AnnRectangleObject();
   rectObj.Rect = new Rect(100, 100, 100, 100);
   rectObj.Stroke = Colors.Blue;
   rectObj.Fill = Colors.Transparent;
   rectObj.StrokeThickness = 1.0;
   container.Children.Add(rectObj);

   AnnLineObject lineObj = new AnnLineObject();
   lineObj.Start = new Point(100, 100);
   lineObj.End = new Point(200, 200);
   lineObj.Stroke = Colors.Red;
   lineObj.StrokeThickness = 1.0;
   container.Children.Add(lineObj);

   MessageBox.Show(string.Format("Before Save: Container has {0} objects", container.Children.Count));

   // create a memory stream to save the objects into
   using(MemoryStream ms = new MemoryStream())
   {
      // save the objects in this container
      AnnCodecs.Save(ms, container);
      ms.Position = 0;

      // clear the container
      container.Children.Clear();
      MessageBox.Show(string.Format("After Save and Clear: Container has {0} objects, Stream size: {1}", container.Children.Count, ms.Length));


      // load the objects back from the stream
      AnnCodecs.Load(ms, container);

      MessageBox.Show(String.Format("After Load: Container has {0} objects", container.Children.Count));
   }
}
SilverlightVBCopy Code
Public Sub AnnCodecs_LoadSaveContainer()
   ' create a new annotation container
   Dim container As AnnContainer = New AnnContainer()
   ' add a few objects into the container

   Dim rectObj As AnnRectangleObject = New AnnRectangleObject()
   rectObj.Rect = New Rect(100, 100, 100, 100)
   rectObj.Stroke = Colors.Blue
   rectObj.Fill = Colors.Transparent
   rectObj.StrokeThickness = 1.0
   container.Children.Add(rectObj)

   Dim lineObj As AnnLineObject = New AnnLineObject()
   lineObj.Start = New Point(100, 100)
   lineObj.End = New Point(200, 200)
   lineObj.Stroke = Colors.Red
   lineObj.StrokeThickness = 1.0
   container.Children.Add(lineObj)

   MessageBox.Show(String.Format("Before Save: Container has {0} objects", container.Children.Count))

   ' create a memory stream to save the objects into
   Using ms As MemoryStream = New MemoryStream()
      ' save the objects in this container
      AnnCodecs.Save(ms, container)
      ms.Position = 0

      ' clear the container
      container.Children.Clear()
      MessageBox.Show(String.Format("After Save and Clear: Container has {0} objects, Stream size: {1}", container.Children.Count, ms.Length))


      ' load the objects back from the stream
      AnnCodecs.Load(ms, container)

      MessageBox.Show(String.Format("After Load: Container has {0} objects", container.Children.Count))
   End Using
End Sub

Remarks

This method will save the annotations to the stream using the AnnCodecsFormat.NativeXml format.

This method will not position the stream back to its original position before it returns. It is your responsibility to position the stream back before you can load objects from this stream.

For more information, refer to WPF Annotation Files.

Requirements

Target Platforms: Silverlight 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only)

See Also

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