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

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:

[C#]

FileStream tiffStream = new FileStream(@"..\..\image.tif", FileMode.Open, FileAccess.ReadWrite);
TiffFile tf = new TiffFile();
tf.Read(tiffStream);
TiffTagCollection tagCol = new TiffTagCollection();
tagCol = tf.Images[i].Tags;
TiffTag tag = tagCol.LookupTag(TiffTagID.WangAnnotationData);
if (tag != null)
tagCol.Remove(tag);
tag = new TiffTag(TiffTagID.WangAnnotationData, data, TiffTagDataType.Byte);
tagCol.Add(tag);
// save the tifffile
string tempPath = System.IO.Path.GetTempFileName();
tf.Save(tempPath);
tiffStream.Close();
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.

[C#]
for
(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();
tf.Read(fs);
byte[] wngData = (byte[])tf.Images[i].Tags.LookupTag(TiffTagID.WangAnnotationData).Data;
fs.Close();
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
MultipageAnnotateVB.zip
MultipageAnnotate.zip

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

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
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, 2017. InstantASP Ltd. All Rights Reserved