Atalasoft Knowledge Base

HOWTO: Save and Load Wang Annotation Data for Multipage TIFF Files


Outdated Content

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

Original Content

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

for (int i = 0; i < tf.Images.Count; i++)
    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.


using (FileStream fs = new FileStream(@"..\..\image.tif", FileMode.Open, FileAccess.Read))
    tiffFile tf = new TiffFile();
    for(int i=0; i< tf.Images.Count; i++)
        // load the image first
        this.annotateViewer1.Images.Insert(i, new AtalaImage(@"..\..\image.tif", i, null));
        // load the data
        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;
        if (wngData.Length > 0)
            this.annotateViewer1.Annotations.Load(wngData, AnnotationDataFormat.Wang);

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

Last Modified: Last Year
Last Modified By: Administrator
Rated 1 star based on 1 vote
Article has been viewed 484 times.
Also In This Category