Groups: Registered, Tech Support, Administrators
Posts: 89
Was thanked: 4 time(s) in 4 post(s)
This example application shows how to programmatically manipulate Annotations in three key ways.
>>Loading
>>Saving
>>Splitting
This has been updated to use with LEADTOOLS v20
*Please note that at the bottom of this page are downloads for each of the test applications shown below
C#Code:class Program
{
private static AnnContainer annContainer;
static void Main(string[] args)
{
string licFile = @"";
string keyFile = "";
RasterSupport.SetLicense(licFile, keyFile);
LoadTifAnnotationsExample();
SaveTifAnnotationsExample();
SplitContainerToTifAndXmlExample();
Console.WriteLine("Done...");
Console.ReadKey();
}
private static void LoadTifAnnotationsExample()
{
AnnCodecs annCodecs = new AnnCodecs();
annContainer = annCodecs.Load(@"C:\Users\cthompson\Desktop\TestFileTifAnnotations.tif", 1);
Console.WriteLine("ANNOTATIONS LOADED: From Test TIF File that Already Contained Annotations:\n");
foreach (var annObject in annContainer.Children)
{
Console.WriteLine($"Annotation: {annObject.ToString()}");
}
Console.WriteLine("\n");
}
private static void SaveTifAnnotationsExample()
{
using (RasterCodecs rasterCodecs = new RasterCodecs())
{
AnnCodecs annCodecs = new AnnCodecs();
RasterTagMetadata tag = annCodecs.SaveToTag(annContainer, false);
rasterCodecs.WriteTag(@"C:\Users\cthompson\Desktop\SaveAnnotationsToTif.tif", 1, tag);
AnnContainer savedTifContainer = annCodecs.Load(@"C:\Users\cthompson\Desktop\SaveAnnotationsToTif.tif", 1);
Console.WriteLine("ANNOTATIONS LOADED: From TIF File the we Saved Annotations to:\n");
foreach (var annObject in savedTifContainer.Children)
{
Console.WriteLine($"Annotation: {annObject.ToString()}");
}
Console.WriteLine("\n");
}
}
private static void SplitContainerToTifAndXmlExample()
{
AnnCodecs annCodecs = new AnnCodecs();
AnnContainer xmlContainer = annContainer.Clone();
for (int i = 0; i < xmlContainer.Children.Count; i++)
{
if (xmlContainer.Children[i].Id != AnnObject.RectangleObjectId)
{
xmlContainer.Children.Remove(xmlContainer.Children[i]);
i--;
}
}
annCodecs.Save(@"C:\Users\cthompson\Desktop\RectangleAnnotationsXml.xml", xmlContainer, AnnFormat.Annotations, 1);
AnnContainer rectangleXmlContainer = annCodecs.Load(@"C:\Users\cthompson\Desktop\RectangleAnnotationsXml.xml", 1);
Console.WriteLine("ANNOTATIONS LOADED: From XML File the we Saved ONLY Rectangle Annotations to:");
foreach (var annObject in rectangleXmlContainer.Children)
{
Console.WriteLine($"Annotation: {annObject.ToString()}");
}
Console.WriteLine("");
AnnContainer tifContainer = annContainer.Clone();
for (int i = 0; i < tifContainer.Children.Count; i++)
{
if (tifContainer.Children[i].Id != AnnObject.NoteObjectId)
{
tifContainer.Children.Remove(tifContainer.Children[i]);
i--;
}
}
using (RasterCodecs rasterCodecs = new RasterCodecs())
{
RasterTagMetadata tag = annCodecs.SaveToTag(tifContainer, false);
rasterCodecs.WriteTag(@"C:\Users\cthompson\Desktop\SaveJustNoteAnnotationsToTif.tif", 1, tag);
}
AnnContainer noteTifContainer = annCodecs.Load(@"C:\Users\cthompson\Desktop\SaveJustNoteAnnotationsToTif.tif", 1);
Console.WriteLine("ANNOTATIONS LOADED: From TIF File the we Saved ONLY Note Annotations to:");
foreach (var annObject in noteTifContainer.Children)
{
Console.WriteLine($"Annotation: {annObject.ToString()}");
}
Console.WriteLine("\n");
}
}
Chris Thompson
Developer Support Engineer
LEAD Technologies, Inc.

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.