LEADTOOLS Annotations (Leadtools.Annotations assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
Save(Stream,AnnContainer,AnnCodecsFormat,Int32,AnnCodecsSavePageMode) Method
See Also 
Leadtools.Annotations Namespace > AnnCodecs Class > Save Method : Save(Stream,AnnContainer,AnnCodecsFormat,Int32,AnnCodecsSavePageMode) Method



stream
The stream to which to save the objects.
container
An AnnContainer containing the objects to be saved.
format
An AnnCodecsFormat value that specifies the annotation format to use when saving.
page
1-based index of the page to be saved.
pageMode
A value that indicates how to handle the page when saving to a multi-page stream.

The Save(Stream,AnnContainer,AnnCodecsFormat,Int32,AnnCodecsSavePageMode) 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.
format
An AnnCodecsFormat value that specifies the annotation format to use when saving.
page
1-based index of the page to be saved.
pageMode
A value that indicates how to handle the page when saving to a multi-page stream.
Saves the annotation objects to a stream.

Syntax

Visual Basic (Declaration) 
Overloads Public Sub Save( _
   ByVal stream As Stream, _
   ByVal container As AnnContainer, _
   ByVal format As AnnCodecsFormat, _
   ByVal page As Integer, _
   ByVal pageMode As AnnCodecsSavePageMode _
) 
Visual Basic (Usage)Copy Code
Dim instance As AnnCodecs
Dim stream As Stream
Dim container As AnnContainer
Dim format As AnnCodecsFormat
Dim page As Integer
Dim pageMode As AnnCodecsSavePageMode
 
instance.Save(stream, container, format, page, pageMode)
C# 
public void Save( 
   Stream stream,
   AnnContainer container,
   AnnCodecsFormat format,
   int page,
   AnnCodecsSavePageMode pageMode
)
C++/CLI 
public:
void Save( 
   Stream^ stream,
   AnnContainer^ container,
   AnnCodecsFormat format,
   int page,
   AnnCodecsSavePageMode pageMode
) 

Parameters

stream
The stream to which to save the objects.
container
An AnnContainer containing the objects to be saved.
format
An AnnCodecsFormat value that specifies the annotation format to use when saving.
page
1-based index of the page to be saved.
pageMode
A value that indicates how to handle the page when saving to a multi-page stream.

Example

Visual BasicCopy Code
Public Sub AnnCodecs_Save()
   ' 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.Bounds = New AnnRectangle(100, 100, 100, 100, AnnUnit.Pixel)
   rectObj.Pen = New AnnPen(Color.Blue, New AnnLength(1, AnnUnit.Pixel))
   rectObj.Brush = Nothing
   container.Objects.Add(rectObj)

   Dim lineObj As AnnLineObject = New AnnLineObject()
   lineObj.StartPoint = New AnnPoint(100, 100, AnnUnit.Pixel)
   lineObj.EndPoint = New AnnPoint(200, 200, AnnUnit.Pixel)
   lineObj.Pen = New AnnPen(Color.Red, New AnnLength(1, AnnUnit.Pixel))
   container.Objects.Add(lineObj)

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

   ' create a memory stream to save the objects into
   Dim ms As MemoryStream = New MemoryStream()
   Try
      ' create a new AnnCodecs class
      Dim codecs As AnnCodecs = New AnnCodecs()

      ' save the objects in this container
      codecs.Save(ms, container, AnnCodecsFormat.Serialize, 1, AnnCodecsSavePageMode.Overwrite)

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

      ' get information about the stream
      ' note, the Save method does not seek the stream back to its original position, so do that now
      ms.Position = 0
      Dim information As AnnCodecsInformation = New AnnCodecsInformation()
      codecs.GetInformation(ms, information)
      MessageBox.Show(String.Format("Format: {0}, Number of pages: {1}", information.Format, information.Pages))

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

      MessageBox.Show(String.Format("After Load: Container has {0} objects", container.Objects.Count))
   Finally
      CType(ms, IDisposable).Dispose()
   End Try
End Sub
C#Copy Code
public void AnnCodecs_Save()
{
   // create a new annotation container
   AnnContainer container = new AnnContainer();
   // add a few objects into the container

   AnnRectangleObject rectObj = new AnnRectangleObject();
   rectObj.Bounds = new AnnRectangle(100, 100, 100, 100, AnnUnit.Pixel);
   rectObj.Pen = new AnnPen(Color.Blue, new AnnLength(1, AnnUnit.Pixel));
   rectObj.Brush = null;
   container.Objects.Add(rectObj);

   AnnLineObject lineObj = new AnnLineObject();
   lineObj.StartPoint = new AnnPoint(100, 100, AnnUnit.Pixel);
   lineObj.EndPoint = new AnnPoint(200, 200, AnnUnit.Pixel);
   lineObj.Pen = new AnnPen(Color.Red, new AnnLength(1, AnnUnit.Pixel));
   container.Objects.Add(lineObj);

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

   // create a memory stream to save the objects into
   using (MemoryStream ms = new MemoryStream())
   {
      // create a new AnnCodecs class
      AnnCodecs codecs = new AnnCodecs();

      // save the objects in this container
      codecs.Save(ms, container, AnnCodecsFormat.Serialize, 1, AnnCodecsSavePageMode.Overwrite);

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

      // get information about the stream
      // note, the Save method does not seek the stream back to its original position, so do that now
      ms.Position = 0;
      AnnCodecsInformation information = new AnnCodecsInformation();
      codecs.GetInformation(ms, information);
      MessageBox.Show(string.Format("Format: {0}, Number of pages: {1}", information.Format, information.Pages));

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

      MessageBox.Show(String.Format("After Load: Container has {0} objects", container.Objects.Count));
   }
}

Remarks

pageMode can be one of the following:

Mode Description
AnnCodecsSavePageMode.Overwrite The stream will be overwritten and all previous information will be lost. The value of page must be 1 or -1 (if appending the objects as the last page).
AnnCodecsSavePageMode.Insert The stream must have valid annotation objects saved to it. The value of page must be between 1 and the total number of pages in the stream. A value of -1 will append the objects as the last page.
AnnCodecsSavePageMode.Replace The stream must have valid annotation objects saved to it. The value of page must be between 1 and total number of pages in the stream.

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.

To save mutliple containers to a multi-page stream using one method, use Save(Stream, AnnContainer[], AnnCodecsFormat).

For more information, refer to Annotation Files.

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7

See Also

Leadtools.Annotations requires a Document or Medical toolkit license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features