Home : Save and Load annotation data for multipage tiff files
Q10130 - HOWTO: Save and Load annotation data for multipage tiff files

NOTE: This article has been flagged by support for review/rewrite. The concept is generally sound but the sample project and finer points need review/rewriting. Please consider creating a support case to ask support for best practices for Multipage TIFF file annotation embedding


There are many different ways to save annotation data for a multi page file.  One of the best ways to do this is by saving the annotation data as metadata into a tiff tag.  With the help of the class TiffFile, this is acctualy really simply to do.

When saving the annotation data, once you have the data into byte array form('data' in this case), this is all you need to do:


FileStream tiffStream = new FileStream(@"..\..\image.tif", FileMode.Open, FileAccess.ReadWrite);
TiffFile tf = new TiffFile();
TiffTagCollection tagCol = new TiffTagCollection();
tagCol = tf.Images[i].Tags;
TiffTag tag = tagCol.LookupTag(TiffTagID.WangAnnotationData);
if (tag != null)
tag = new TiffTag(TiffTagID.WangAnnotationData, data, TiffTagDataType.Byte);
// save the tifffile
string tempPath = System.IO.Path.GetTempFileName();
File.Copy(tempPath, @"..\..\image.tif", true);


When loading the data into the annotate viewer, this requires a few more steps.  Remember to set the MultipageAnnotateMode property to true, so that the viewer knows to switch the annotation layers with the images.  The coralation between the layer index number and the image index number is what the viewer follows.

(int i=0; i< 3; i++)
// load the image first
this.annotateViewer1.Images.Insert(i, new AtalaImage(@"..\..\image.tif",i,null));
// load the data
FileStream fs = new FileStream(@"..\..\image.tif", FileMode.Open, FileAccess.Read);
TiffFile tf = new TiffFile();
byte[] wngData = (byte[])tf.Images[i].Tags.LookupTag(TiffTagID.WangAnnotationData).Data;
Layer l = new Layer("Layer for page "+i.ToString(),false);
this.annotateViewer1.Annotations.Layers.Insert(i, l);
this.annotateViewer1.Annotations.CurrentLayer = l;
this.annotateViewer1.Annotations.Load(wngData, AnnotationDataFormat.Wang);

There is a sample project attached, with a VB.NET version as well, that demonstrates how to save and load annotation data from a tiff file. The data is saved as Wang format embeded into a tiff tag. The "Save annotation data" button simply loads the data from the 3 .wng files and saves it into the tiff tag for wang annotation data. The idea here is that you could get this annotation data from anywhere, its just easy for this demo to grab it from a file.

When you click "load image", the program will load the 3 page image and its multipage annotation data. After you click this button, no image will appear in the control, but if you hit "next" the image will be shown as expected.

Related Articles
No Related Articles Available.

Article Attachments

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?


Tell us why you rated the content this way. (optional)
Approved Comments...
No user comments available for this article.

Powered By InstantKB.NET v1.3
Copyright © 2002, 2020. InstantASP Ltd. All Rights Reserved