LEADTOOLS Image File Support (Leadtools.Codecs assembly)

Tags Property (CodecsLoadOptions)

Show in webframe
Example 







Gets or sets a value that indicates whether any tags found in the file should be automatically loaded.
Syntax
public bool Tags {get; set;}
'Declaration
 
Public Property Tags As Boolean
'Usage
 
Dim instance As CodecsLoadOptions
Dim value As Boolean
 
instance.Tags = value
 
value = instance.Tags
public bool Tags {get; set;}
@property (nonatomic, assign) BOOL tags;
public boolean getTags()
public void setTags(boolean value)
            
 
get_Tags();
set_Tags(value);
Object.defineProperty('Tags');
public:
property bool Tags {
   bool get();
   void set (    bool value);
}

Property Value

true to automatically load any tags found in the file; otherwise it is false.
Remarks

When the value of the Tags property is set to true, any subsequent load operation performed by this RasterCodecs object will automatically try to load all the tags found in the file and store them in the RasterImage.Tags collection of the resulting image.

Internally, the RasterCodecs object will call RasterCodecs.TagsSupported on the image and only tries to load the tags if the value returned was true.

When loading more than one page from a multi-page file, only the tags found in the first page will be automatically loaded when the value of this property is set to true. To manually load all the tags in any page, use RasterCodecs.ReadTags.

You must set the value of the Markers property to false to enable automatically loading the tags. If the value of both Markers and Tags is set to true, then the markers will take take precedence and no tags will be loaded.

Note that any load method that uses tiles, offset or resizing will not load any file metadata automatically regardless of the value of this property.

Example
Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.Drawing

Public Sub MetadataAutoLoadExample()
   ' Prompt the user for an image file
   Dim imageFileName As String = PromptForFileName()
   ' Initialize LEADTOOLS
   Using codecs As New RasterCodecs()
      Dim loadOptions As CodecsLoadOptions = codecs.Options.Load

      ' Make sure auto-loading of markers is turned off, otherwise,
      ' markers take precedence over loading the other metadata
      loadOptions.Markers = False

      ' Automatically load any tags, comments and geokeys found in this file
      loadOptions.Tags = True
      loadOptions.Comments = True
      loadOptions.GeoKeys = True

      ' Now load the image
      Using image As RasterImage = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)
         Dim txtFileName As String = Path.Combine( _
            Path.GetDirectoryName(imageFileName), _
            Path.GetFileNameWithoutExtension(imageFileName) + "_metadata.txt")

         Using writer As StreamWriter = File.CreateText(txtFileName)
            ' Show its tags
            ShowTags(writer, "Tags", image.Tags)

            ' Show its comments
            ShowComments(writer, image.Comments)

            ' Show its geo keys (tags and geokeys use the same data type)
            ShowTags(writer, "GeoKeys", image.GeoKeys)
         End Using

         ' Show the text file we created
         System.Diagnostics.Process.Start(txtFileName)
      End Using
   End Using
End Sub

Private Shared Sub ShowTags(ByVal writer As StreamWriter, ByVal name As String, ByVal tags As RasterCollection(Of RasterTagMetadata))
   writer.WriteLine("{0}:", name)

   For Each tag As RasterTagMetadata In tags
      writer.WriteLine("Id: 0x{0}, data length: {1}", tag.Id.ToString("X"), tag.GetData().Length)
   Next

   writer.WriteLine()
End Sub

Private Shared Sub ShowComments(ByVal writer As StreamWriter, ByVal comments As RasterCollection(Of RasterCommentMetadata))
   writer.WriteLine("Comments:")

   For Each comment As RasterCommentMetadata In comments
      writer.WriteLine("Type: 0x{0}, data length: {1}", comment.Type, comment.GetData().Length)
   Next

   writer.WriteLine()
End Sub
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;

public void MetadataAutoLoadExample()
{
   // Prompt the user for an image file
   string imageFileName = PromptForFileName();
   // Initialize LEADTOOLS
   using (RasterCodecs codecs = new RasterCodecs())
   {
      CodecsLoadOptions loadOptions = codecs.Options.Load;

      // Make sure auto-loading of markers is turned off, otherwise,
      // markers take precedence over loading the other metadata
      loadOptions.Markers = false;

      // Automatically load any tags, comments and geokeys found in this file
      loadOptions.Tags = true;
      loadOptions.Comments = true;
      loadOptions.GeoKeys = true;

      // Now load the image
      using (RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1))
      {
         string txtFileName = Path.Combine(
            Path.GetDirectoryName(imageFileName),
            Path.GetFileNameWithoutExtension(imageFileName) + "_metadata.txt");

         using (StreamWriter writer = File.CreateText(txtFileName))
         {
            // Show its tags
            ShowTags(writer, "Tags", image.Tags);

            // Show its comments
            ShowComments(writer, image.Comments);

            // Show its geo keys (tags and geokeys use the same data type)
            ShowTags(writer, "GeoKeys", image.GeoKeys);
         }

         // Show the text file we created
         System.Diagnostics.Process.Start(txtFileName);
      }
   }
}

private static void ShowTags(StreamWriter writer, string name, RasterCollection<RasterTagMetadata> tags)
{
   writer.WriteLine("{0}:", name);

   foreach (RasterTagMetadata tag in tags)
   {
      writer.WriteLine("Id: 0x{0}, data length: {1}", tag.Id.ToString("X"), tag.GetData().Length);
   }

   writer.WriteLine();
}

private static void ShowComments(StreamWriter writer, RasterCollection<RasterCommentMetadata> comments)
{
   writer.WriteLine("Comments:");

   foreach (RasterCommentMetadata comment in comments)
   {
      writer.WriteLine("Type: 0x{0}, data length: {1}", comment.Type, comment.GetData().Length);
   }

   writer.WriteLine();
}
RasterCodecsExamples.prototype.MetadataAutoLoadExample = function ( )
{
   Tools.SetLicense ( ) ;
   with (Leadtools) {
      with (Leadtools.Codecs) {
         //Point this to a file with tags, comments, or geokeys
         var imageFileName = "Assets\\3polars.tif";

         // Initialize LEADTOOLS
         var codecs = new RasterCodecs();
         var image;
         var loadOptions = codecs.options.load;
         var writer;
         // Make sure auto-loading of markers is turned off, otherwise,
         // markers take precedence over loading the other metadata
         loadOptions.markers = false;

         // Automatically load any tags, comments and geokeys found in this file
         loadOptions.tags = true;
         loadOptions.comments = true;
         loadOptions.geoKeys = true;

         // Now load the image
         return Tools.AppInstallFolder().getFileAsync(imageFileName).then(function (loadFile) {
            return codecs.loadAsync(LeadStreamFactory.create(loadFile), 0, CodecsLoadByteOrder.bgrOrGray, 1, 1)
         })
         .then(function (img) {
            image = img;
            var txtFileName = "image_metadata.txt";
            return Tools.AppLocalFolder().createFileAsync(txtFileName)
         })
         .then(function (saveFile) {
            return saveFile.openAsync(Windows.Storage.FileAccessMode.readWrite)
         })
         .then(function (stream) {
            writer = Windows.Storage.Streams.DataWriter(stream);

            // Show its tags
            ShowTags(writer, "Tags", image.tags);

            // Show its comments
            ShowComments(writer, image.comments);

            // Show its geo keys (tags and geokeys use the same data type)
            ShowTags(writer, "GeoKeys", image.geoKeys);

            return writer.storeAsync ()}).then ( function ( ){
               image.close();
               writer.close();
            
            codecs.close();
         });
      }
   }
}

function ShowTags(writer, name, tags)
{
   writer.writeString(name + ":\n");  

   for ( var i =0; i < tags.length; i++ )
   {
      var tag = tags[i];
      writer.writeString("Id: " + tag.id.toString() + ", data length: " + tag.getData().length);
   }

   writer.writeString("\n\n");
}

function ShowComments(writer, comments)
{
   writer.writeString("Comments:");

   for ( var i =0; i <comments.length; i++ )
   {
      var comment = comments[i];
      writer.writeString("Type: 0x" + comment.type + ", data length: " + comment.getData().length);
   }

   writer.writeString("\n\n");
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;

      
public async Task MetadataAutoLoadExample()
{
   //Point this to a file with tags, comments, or geokeys
   string imageFileName = _tifFileWithTags;
   // Initialize LEADTOOLS
   using (RasterCodecs codecs = new RasterCodecs())
   {
      CodecsLoadOptions loadOptions = codecs.Options.Load;

      // Make sure auto-loading of markers is turned off, otherwise,
      // markers take precedence over loading the other metadata
      loadOptions.Markers = false;

      // Automatically load any tags, comments and geokeys found in this file
      loadOptions.Tags = true;
      loadOptions.Comments = true;
      loadOptions.GeoKeys = true;

      // Now load the image
      StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(imageFileName);
      using (RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile), 0, CodecsLoadByteOrder.BgrOrGray, 1, 1))
      {
         string txtFileName = Path.GetFileNameWithoutExtension(imageFileName) + "_metadata.txt";
         StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(txtFileName);
         using (StreamWriter writer = new StreamWriter(await saveFile.OpenStreamForWriteAsync()))
         {
            // Show its tags
            ShowTags(writer, "Tags", image.Tags);

            // Show its comments
            ShowComments(writer, image.Comments);

            // Show its geo keys (tags and geokeys use the same data type)
            ShowTags(writer, "GeoKeys", image.GeoKeys);
         }
      }
   }
}

private static void ShowTags(StreamWriter writer, string name, IList<RasterTagMetadata> tags)
{
   writer.WriteLine("{0}:", name);

   foreach (RasterTagMetadata tag in tags)
   {
      writer.WriteLine("Id: 0x{0}, data length: {1}", tag.Id.ToString("X"), tag.GetData().Length);
   }

   writer.WriteLine();
}

private static void ShowComments(StreamWriter writer, IList<RasterCommentMetadata> comments)
{
   writer.WriteLine("Comments:");

   foreach (RasterCommentMetadata comment in comments)
   {
      writer.WriteLine("Type: 0x{0}, data length: {1}", comment.Type, comment.GetData().Length);
   }

   writer.WriteLine();
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Examples;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;
using Leadtools.Windows.Media;

public void MetadataAutoLoadExample(Stream inStreamImage, StreamWriter outStreamText)
{
   // Initialize LEADTOOLS
   RasterCodecs codecs = new RasterCodecs();
   {
      CodecsLoadOptions loadOptions = codecs.Options.Load;
      // Make sure auto-loading of markers is turned off, otherwise,
      // markers take precedence over loading the other metadata
      loadOptions.Markers = false;

      // Automatically load any tags, comments and geokeys found in this file
      loadOptions.Tags = true;
      loadOptions.Comments = true;
      loadOptions.GeoKeys = true;

      using (RasterImage image = codecs.Load(inStreamImage, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1))
      {
         // Show its tags
         ShowTags(outStreamText, "Tags", image.Tags);

         // Show its comments
         ShowComments(outStreamText, image.Comments);

         // Show its geo keys (tags and geokeys use the same data type)
         ShowTags(outStreamText, "GeoKeys", image.GeoKeys);
      }
   }
}

private static void ShowTags(StreamWriter writer, string name, RasterCollection<RasterTagMetadata> tags)
{
   writer.WriteLine("{0}:", name);

   foreach(RasterTagMetadata tag in tags)
   {
      writer.WriteLine("Id: 0x{0}, data length: {1}", tag.Id.ToString("X"), tag.GetData().Length);
   }

   writer.WriteLine();
}

private static void ShowComments(StreamWriter writer, RasterCollection<RasterCommentMetadata> comments)
{
   writer.WriteLine("Comments:");

   foreach(RasterCommentMetadata comment in comments)
   {
      writer.WriteLine("Type: 0x{0}, data length: {1}", comment.Type, comment.GetData().Length);
   }

   writer.WriteLine();
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.Windows.Media

Public Sub MetadataAutoLoadExample(ByVal inStreamImage As Stream, ByVal outStreamText As StreamWriter)
   ' Initialize LEADTOOLS
   Dim codecs As RasterCodecs = New RasterCodecs()
      Dim loadOptions As CodecsLoadOptions = codecs.Options.Load
      ' Make sure auto-loading of markers is turned off, otherwise,
      ' markers take precedence over loading the other metadata
      loadOptions.Markers = False

      ' Automatically load any tags, comments and geokeys found in this file
      loadOptions.Tags = True
      loadOptions.Comments = True
      loadOptions.GeoKeys = True

      Using image As RasterImage = codecs.Load(inStreamImage, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)
         ' Show its tags
         ShowTags(outStreamText, "Tags", image.Tags)

         ' Show its comments
         ShowComments(outStreamText, image.Comments)

         ' Show its geo keys (tags and geokeys use the same data type)
         ShowTags(outStreamText, "GeoKeys", image.GeoKeys)
      End Using
End Sub

Private Shared Sub ShowTags(ByVal writer As StreamWriter, ByVal name As String, ByVal tags As RasterCollection(Of RasterTagMetadata))
   writer.WriteLine("{0}:", name)

   For Each tag As RasterTagMetadata In tags
      writer.WriteLine("Id: 0x{0}, data length: {1}", tag.Id.ToString("X"), tag.GetData().Length)
   Next tag

   writer.WriteLine()
End Sub

Private Shared Sub ShowComments(ByVal writer As StreamWriter, ByVal comments As RasterCollection(Of RasterCommentMetadata))
   writer.WriteLine("Comments:")

   For Each comment As RasterCommentMetadata In comments
      writer.WriteLine("Type: 0x{0}, data length: {1}", comment.Type, comment.GetData().Length)
   Next comment

   writer.WriteLine()
End Sub
Requirements

Target Platforms

See Also

Reference

CodecsLoadOptions Class
CodecsLoadOptions Members
Implementing TIFF Comments and Tags

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.