Home : TIFF : Tiff Tags : Copy XMP from one TIFF to another
Q10294 - HOWTO: Copy XMP from one TIFF to another

The best way to copy XMP annotation data from one TIFF into another is by using the TiffFile class.  With TiffFile you can copy the tags without having to load the images into memory; this improves performance and reduces the application memory requirements.

Below is the core of the code, which simply loops through each page, removes any existing XMP tag and adds the new tag:

[C#]
TiffFile tfIn = new TiffFile();
TiffFile tfOut = new TiffFile();
tfIn.Read(fsIn); tfOut.Read(fsOut);
for (int i = 0; i < frameCount; i++) { TiffDirectory img = tfOut.Images[i];
// If the output file already has this tag, remove it. TiffTag xmpTag = img.Tags.LookupTag(TiffTagID.XmpData); if (xmpTag != null) img.Tags.Remove(xmpTag);
xmpTag = tfIn.Images[i].Tags.LookupTag(TiffTagID.XmpData); if (xmpTag != null) img.Tags.Add(new TiffTag(TiffTagID.XmpData, xmpTag.Data, xmpTag.Type)); }
[VB.NET]
Dim tfIn As New TiffFile()
Dim tfOut As New TiffFile()
tfIn.Read(fsIn) tfOut.Read(fsOut)
For i As Integer = 0 To frameCount - 1 Dim img As TiffDirectory = tfOut.Images(i)
' If the output file already has this tag, remove it. Dim xmpTag As TiffTag = img.Tags.LookupTag(TiffTagID.XmpData) If xmpTag IsNot Nothing Then img.Tags.Remove(xmpTag) End If
xmpTag = tfIn.Images(i).Tags.LookupTag(TiffTagID.XmpData) If xmpTag IsNot Nothing Then img.Tags.Add(New TiffTag(TiffTagID.XmpData, xmpTag.Data, xmpTag.Type)) End If Next i

The full source for a console application is attached.

Related Articles
No Related Articles Available.

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