Home : Annotations : Storage : Embed XMP data into a TIFF file.
Q10220 - HOWTO: Embed XMP data into a TIFF file.

This document is for annotations in DotImage Document Imaging / DotAnnotate 5.0 or higher. Instructions for earlier versions can be found at http://www.atalasoft.com/KB/article.aspx?id=10111.

XMP annotation data can be embedded into a TIFF file rather than saving it as a separate file. This is done by saving the annotations into an XMP packet with the XmpFormatter and embedding the data into the XMP TIFF tag. Below is a code example:

[C#]
using Atalasoft.Annotate;
using Atalasoft.Annotate.UI;
using Atalasoft.Annotate.Formatters;
using Atalasoft.Imaging;
using Atalasoft.Imaging.Codec;
using System.IO;
//...

private void SaveXmpToTiff(Stream outputStream, AnnotateViewer viewer)
{
  SaveXmpToTiff(outputStream, viewer.Annotations, viewer.Image);
}

private void SaveXmpToTiff(Stream outputStream, AnnotationController controller, AtalaImage image)
{
  // Create an XmpFormatter and tell it to create a packet.
  // Packets are required when embedding the data into an image.
  XmpFormatter formatter = new XmpFormatter();
  formatter.CreateXmpPacket = true;
// Create a TiffEncoder and set its Xmp property to the annotation data. TiffEncoder tif = new TiffEncoder(); tif.Xmp = controller.Save(formatter);
// Save the Tiff. tif.Save(outputStream, image, null); } [VB.NET] Imports Atalasoft.Annotate Imports Atalasoft.Annotate.UI Imports Atalasoft.Annotate.Formatters Imports Atalasoft.Imaging Imports Atalasoft.Imaging.Codec Imports System.IO '... Private Sub SaveXmpToTiff(ByVal outputStream As Stream, ByVal viewer As AnnotateViewer) SaveXmpToTiff(outputStream, viewer.Annotations, viewer.Image) End Sub Private Sub SaveXmpToTiff(ByVal outputStream As Stream, ByVal controller As AnnotationController, ByVal image As AtalaImage) ' Create an XmpFormatter and tell it to create a packet. ' Packets are required when embedding the data into an image. Dim formatter As XmpFormatter = New XmpFormatter() formatter.CreateXmpPacket = True ' Create a TiffEncoder and set its Xmp property to the annotation data. Dim tif As TiffEncoder = New TiffEncoder() tif.Xmp = controller.Save(formatter) ' Save the Tiff. tif.Save(outputStream, image, Nothing) End Sub

To read the XMP annotation back into DotAnnotate, you can either use the AnnotateViewer.Open method with the loadAnnotations argument set to true or you can manually extract the XMP TIFF tag data using the following code.

[C#]
using Atalasoft.Annotate.UI;
using Atalasoft.Annotate.Formatters;using Atalasoft.Imaging.Metadata;using Atalasoft.Imaging.Codec;using System.IO;
//...

private void LoadXmpFromTiff(Stream inputStream, AnnotateViewer viewer)
{  
    TiffTag tag = TiffDecoder.GetTiffTag((int)TiffTagID.XmpData, inputStream, 0);
    if (tag != null) 
        viewer.Annotations.Load((byte[])tag.Data, new XmpFormatter());
}

[VB.NET]
Imports Atalasoft.Annotate.UI
Imports Atalasoft.Annotate.Formatters
Imports Atalasoft.Imaging.Codec
Imports Atalasoft.Imaging.Metadata
Imports System.IO
'... 

Private Sub LoadXmpFromTiff(ByVal inputStream As Stream, ByVal viewer As AnnotateViewer)  
    Dim tag As TiffTag = TiffDecoder.GetTiffTag(CType(TiffTagID.XmpData, Integer), inputStream, 0)
    If Not tag Is Nothing Then
        viewer.Annotations.Load(CType(tag.Data, Byte()), New XmpFormatter())
    End If
End Sub

Related Articles
No Related Articles Available.

Article Attachments
EmbeddedXMPSaveLoad.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