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)); } } |