LEADTOOLS Image File Support (Leadtools.Codecs assembly)
LEAD Technologies, Inc

EnumTags(String,Int32) Method

Example 





A System.String containing the input file name.
1-based index of the page from which to enumerate the tags.
Enumerates all the tags in a file. .NET support Silverlight support
Syntax
public void EnumTags( 
   string fileName,
   int pageNumber
)
'Declaration
 
Public Overloads Sub EnumTags( _
   ByVal fileName As String, _
   ByVal pageNumber As Integer _
) 
'Usage
 
Dim instance As RasterCodecs
Dim fileName As String
Dim pageNumber As Integer
 
instance.EnumTags(fileName, pageNumber)
public void EnumTags( 
   string fileName,
   int pageNumber
)
 function Leadtools.Codecs.RasterCodecs.EnumTags(String,Int32)( 
   fileName ,
   pageNumber 
)
public:
void EnumTags( 
   String^ fileName,
   int pageNumber
) 

Parameters

fileName
A System.String containing the input file name.
pageNumber
1-based index of the page from which to enumerate the tags.
Remarks

This method will fire the TagFound event for each tag found in the file.

Currently, only TIFF and Exif files contain tags.

For multipage TIFF files, you can enumerate the tags from a particular page. Specify the page number whose tags to enumerate.

This method enumerates the standard TIFF tags and the user tags. Standard TIFF tags are less than 32767. User TIFF tags are usually between 32768 and 65535.

To enumerate the tags stored in a stream, use EnumTags(Stream,Int32).

To read a tag value, use ReadTag(String,Int32,Int32) and to read all the tags in a file, use ReadTags(String,Int32).

For general information about TIFF tags, refer to Implementing TIFF Comments and Tags.

Do not attempt to use DeleteTag(String,Int32,Int32) to delete tags from inside the TagFound event. If you want to delete tags that you enumerate, use this event to add the tags to a list. Upon returning from EnumTags(String,Int32), you can delete all the tags from the list.

You can use TagsSupported to determine whether a certain file format supports tags.

Example
 
Private tagsFileName As String
Private myTags As RasterCollection(Of RasterTagMetadata)
Private Sub EnumTagsExample(ByVal srcFileName As String, ByVal destFileName As String)
   Dim codecs As RasterCodecs = New RasterCodecs()

   tagsFileName = srcFileName
   myTags = New RasterCollection(Of RasterTagMetadata)()

   AddHandler codecs.TagFound, AddressOf codecs_TagFound
   codecs.EnumTags(srcFileName, 1)
   RemoveHandler codecs.TagFound, AddressOf codecs_TagFound

   ' We read all the tags now, save them to the file
   Console.WriteLine("{0} tags read, saving them to the destination file", myTags.Count)
   codecs.WriteTags(destFileName, 1, myTags)

   ' Clean up
   codecs.Dispose()
End Sub

Private Sub codecs_TagFound(ByVal sender As Object, ByVal e As CodecsEnumTagsEventArgs)
   Console.WriteLine("Tag: Id={0}, Count={1}, Type={2}", e.Id, e.Count, e.MetadataType)

   ' Read this tag from the file and add it to our collection
   Dim codecs As RasterCodecs = TryCast(sender, RasterCodecs)
   Dim tag As RasterTagMetadata = codecs.ReadTag(tagsFileName, 1, e.Id)
   myTags.Add(tag)
End Sub
string tagsFileName;
RasterCollection<RasterTagMetadata> myTags;
void EnumTagsExample(string srcFileName, string destFileName)
{
    RasterCodecs codecs = new RasterCodecs();

    tagsFileName = srcFileName;
    myTags = new RasterCollection<RasterTagMetadata>();

    codecs.TagFound += new EventHandler<CodecsEnumTagsEventArgs>(codecs_TagFound);
    codecs.EnumTags(srcFileName, 1);
    codecs.TagFound -= new EventHandler<CodecsEnumTagsEventArgs>(codecs_TagFound);

    // We read all the tags now, save them to the file
    Console.WriteLine("{0} tags read, saving them to the destination file", myTags.Count);
    codecs.WriteTags(destFileName, 1, myTags);

    // Clean up
    codecs.Dispose();
}

void codecs_TagFound(object sender, CodecsEnumTagsEventArgs e)
{
    Console.WriteLine("Tag: Id={0}, Count={1}, Type={2}", e.Id, e.Count, e.MetadataType);

    // Read this tag from the file and add it to our collection
    RasterCodecs codecs = sender as RasterCodecs;
    RasterTagMetadata tag = codecs.ReadTag(tagsFileName, 1, e.Id);
    myTags.Add(tag);
}
RasterCodecsExamples.prototype.EnumTagsExample_Runner = function ( )
{
   Tools.SetLicense ( ) ;
   with ( Leadtools ) { with ( Leadtools.Codecs ) { 
      var srcImage;
      var codecs = new RasterCodecs();
      var tifFileWithTags = "Assets\\3polars.tif";
      // save a GEO TIFF file first, b/c the example needs one
      var destFileName = "WriteTags.tif";
      return Tools.AppLocalFolder().createFileAsync(destFileName).then ( function ( saveFile ) {
         srcImage = RasterImage.create(100, 100, 24, 96, RasterColorHelper.black);
         return codecs.saveAsync(srcImage, LeadStreamFactory.create(saveFile), RasterImageFormat.tif, 24)})
      .then ( function ( ) {
         srcImage.close();
         codecs.close();

         return EnumTagsExample(tifFileWithTags, destFileName);
      });
   }
   }
}

   var tagsFileName;
   var myTags;

   function EnumTagsExample(srcFileName, destFileName) {
      Tools.SetLicense();
      with (Leadtools) {
         with (Leadtools.Codecs) {
            var codecs = new RasterCodecs();
            Leadtools.RasterSupport.initialize();
            codecs.eventsDispatchMode = Leadtools.LeadEventsDispatchMode.useCoreDispatcher;
            codecs.addEventListener("tagfound", codecs_TagFound);
            
            tagsFileName = srcFileName;
            myTags = new Array();

            return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {


               
               return codecs.enumTagsAsync(LeadStreamFactory.create(loadFile), 1)
            })
               .then(function () {
                  codecs.removeEventListener("tagfound", codecs_TagFound);

                  // We read all the tags now, save them to the file
                  console.info(myTags.length, " tags read, saving them to the destination file");
                  return Tools.AppLocalFolder().createFileAsync(destFileName, Windows.Storage.CreationCollisionOption.openIfExists)
               })
               .then(function (saveFile) {
                  return codecs.writeTagsAsync(LeadStreamFactory.create(saveFile), 1, myTags)
               })
               .then(function () {
                  // Clean up
                  codecs.close();
               });
         }
      }
   }

function codecs_TagFound(e) {
   console.info("Tag: Id=" + e.id + ", Count=" + e.count + " Type=", e.metadataType);

   // Read this tag from the file and add it to our collection
   var codecs = e.target;
   return Tools.AppInstallFolder().getFileAsync(tagsFileName).then(function (loadFile) {
      return codecs.readTagAsync(Leadtools.LeadStreamFactory.create(loadFile), 1, e.id)
   })
      .then(function (tag) {
         myTags.push(tag);
      });
}
string tagsFileName;
List<RasterTagMetadata> myTags;
async Task EnumTagsExample(string srcFileName, string destFileName)
{
   RasterCodecs codecs = new RasterCodecs();

   try
   {
      tagsFileName = srcFileName;
      myTags = new List<RasterTagMetadata>();

      StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);

      codecs.TagFound += new EventHandler<CodecsEnumTagsEventArgs>(codecs_TagFound);
      await codecs.EnumTagsAsync(LeadStreamFactory.Create(loadFile), 1);
      codecs.TagFound -= new EventHandler<CodecsEnumTagsEventArgs>(codecs_TagFound);

      // We read all the tags now, save them to the file
      Debug.WriteLine("{0} tags read, saving them to the destination file", myTags.Count);
      StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName, CreationCollisionOption.OpenIfExists);
      await codecs.WriteTagsAsync(LeadStreamFactory.Create(saveFile), 1, myTags);
   }
   catch (Exception ex)
   {
      string error = "";
      RasterException rasterException = RasterException.FromHResult(ex.HResult);
      if (rasterException != null)
         error = rasterException.Message;
      else
         error = ex.Message;
      Debug.WriteLine(error);
      Assert.Fail(error);
   }

   // Clean up
   codecs.Dispose();
}

async void codecs_TagFound(object sender, CodecsEnumTagsEventArgs e)
{
   Debug.WriteLine("Tag: Id={0}, Count={1}, Type={2}", e.Id, e.Count, e.MetadataType);

   // Read this tag from the file and add it to our collection
   RasterCodecs codecs = sender as RasterCodecs;
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(tagsFileName);
   RasterTagMetadata tag = await codecs.ReadTagAsync(LeadStreamFactory.Create(loadFile), 1, e.Id);
   myTags.Add(tag);
}
Stream tagsStream;
RasterCollection<RasterTagMetadata> myTags;
void EnumTagsExample(Stream inStreamTif, Stream outStreamTif)
{
   RasterCodecs codecs = new RasterCodecs();

   tagsStream = inStreamTif;
   myTags = new RasterCollection<RasterTagMetadata>();

   codecs.TagFound += new EventHandler<CodecsEnumTagsEventArgs>(codecs_TagFound);
   codecs.EnumTags(inStreamTif, 1);
   codecs.TagFound -= new EventHandler<CodecsEnumTagsEventArgs>(codecs_TagFound);

   // We read all the tags now, save them to the file
   Debug.WriteLine("{0} tags read, saving them to the destination file", myTags.Count);
   codecs.WriteTags(outStreamTif, 1, myTags);
}

void codecs_TagFound(object sender, CodecsEnumTagsEventArgs e)
{
   Debug.WriteLine("Tag: Id={0}, Count={1}, Type={2}", e.Id, e.Count, e.MetadataType);

   // Read this tag from the file and add it to our collection
   RasterCodecs codecs = sender as RasterCodecs;
   RasterTagMetadata tag = codecs.ReadTag(tagsStream, 1, e.Id);
   myTags.Add(tag);
}
Private tagsStream As Stream
Private myTags As RasterCollection(Of RasterTagMetadata)
Private Sub EnumTagsExample(ByVal inStreamTif As Stream, ByVal outStreamTif As Stream)
   Dim codecs As RasterCodecs = New RasterCodecs()

   tagsStream = inStreamTif
   myTags = New RasterCollection(Of RasterTagMetadata)()

   AddHandler codecs.TagFound, AddressOf codecs_TagFound
   codecs.EnumTags(inStreamTif, 1)
   RemoveHandler codecs.TagFound, AddressOf codecs_TagFound

   ' We read all the tags now, save them to the file
   Debug.WriteLine("{0} tags read, saving them to the destination file", myTags.Count)
   codecs.WriteTags(outStreamTif, 1, myTags)
End Sub

Private Sub codecs_TagFound(ByVal sender As Object, ByVal e As CodecsEnumTagsEventArgs)
   Debug.WriteLine("Tag: Id={0}, Count={1}, Type={2}", e.Id, e.Count, e.MetadataType)

   ' Read this tag from the file and add it to our collection
   Dim codecs As RasterCodecs = TryCast(sender, RasterCodecs)
   Dim tag As RasterTagMetadata = codecs.ReadTag(tagsStream, 1, e.Id)
   myTags.Add(tag)
End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

RasterCodecs Class
RasterCodecs Members
Overload List

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.