LEADTOOLS (Leadtools assembly)
LEAD Technologies, Inc

Tags Property

Example 





The collection of tag data used when reading and writing certain file formats (including TIFF). .NET support Silverlight support
Syntax
'Declaration
 
Public ReadOnly Property Tags As RasterCollection(Of RasterTagMetadata)
'Usage
 
Dim instance As RasterImage
Dim value As RasterCollection(Of RasterTagMetadata)
 
value = instance.Tags
 get_Tags(); 

Property Value

A collection of RasterTagMetadata used when reading and writing certain file formats (including TIFF).
Remarks

Several formats allow you to store non-image data such as comments, tags, and markers.

You can manipulate the tags of an image by adding/removing RasterTagMetadata objects to this collection.

By setting the CodecsSaveOptions.Tags property to true before calling RasterCodecs.Save, you can save the tags in this collection when the image is saved into a file.

By setting the CodecsLoadOptions.Markers property to true before calling RasterCodecs.Load, you can load all the markers (if any) into this collection when an image is loaded from a file.

You can use the RasterCodecs.WriteTags method to save the tags directly to an existing file and the RasterCodecs.EnumTags to load the tags stored in an existing file.

For more information, refer to Non Image Data.

Example
 
Private Sub DisplayTag(ByVal tag As RasterTagMetadata)
      Select Case tag.DataType
         Case RasterTagMetadataDataType.Ascii
            MessageBox.Show("Tag " & tag.Id.ToString() & " = " & tag.ToAscii())
         Case RasterTagMetadataDataType.Byte
            MessageBox.Show("Tag " & tag.Id.ToString() & " = " & tag.ToByte()(0).ToString())
      End Select
   End Sub
   Public Sub TagsExample()
      Dim codecs As RasterCodecs = New RasterCodecs()
      Dim image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1.CMP"))

      'Ascii
      Dim tagDataAscii As RasterTagMetadata = New RasterTagMetadata()
      ' set the Copyright tag
      tagDataAscii.Id = &H8000
      tagDataAscii.DataType = RasterTagMetadataDataType.Ascii
      tagDataAscii.FromAscii("Test String")
      image.Tags.Add(tagDataAscii)

      'Byte
      Dim tagDataByte As RasterTagMetadata = tagDataAscii.Clone()
      tagDataAscii.Id = &H8001
      tagDataByte.DataType = RasterTagMetadataDataType.Byte
      Dim byteArray As Byte() = New Byte(0) {}
      byteArray(0) = 10
      tagDataByte.FromByte(byteArray)
      image.Tags.Add(tagDataByte)

      codecs.Options.Save.Tags = True
      codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1_TAGS.TIF"), RasterImageFormat.Tif, 0)
      ' load the tags together with the image

      Dim tag As RasterTagMetadata = codecs.ReadTag(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1_TAGS.TIF"), 1, &H8000)
      DisplayTag(tag)
      tag = codecs.ReadTag(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1_TAGS.TIF"), 1, &H8001)
      DisplayTag(tag)

      codecs.Dispose()
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
private void DisplayTag(RasterTagMetadata tag)
   {
      switch(tag.DataType)
      {
         case RasterTagMetadataDataType.Ascii:
            MessageBox.Show("Tag " + tag.Id.ToString() + " = " + tag.ToAscii());
            break;
         case RasterTagMetadataDataType.Byte:
            MessageBox.Show("Tag " + tag.Id.ToString() + " = " + tag.ToByte()[0].ToString());
            break;
      }
   }
   public void TagsExample()
   {
      RasterCodecs codecs = new RasterCodecs();
      RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1.CMP"));

      //Ascii
      RasterTagMetadata tagDataAscii = new RasterTagMetadata();
      // set the Copyright tag
      tagDataAscii.Id = 0x8000;
      tagDataAscii.DataType = RasterTagMetadataDataType.Ascii;
      tagDataAscii.FromAscii("Test String");
      image.Tags.Add(tagDataAscii);

      //Byte
      RasterTagMetadata tagDataByte = tagDataAscii.Clone();
      tagDataAscii.Id = 0x8001;
      tagDataByte.DataType = RasterTagMetadataDataType.Byte;
      byte[] byteArray = new byte[1];
      byteArray[0] = 10;
      tagDataByte.FromByte(byteArray);
      image.Tags.Add(tagDataByte);

      codecs.Options.Save.Tags = true;
      codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1_TAGS.TIF"), RasterImageFormat.Tif, 0);
      // load the tags together with the image

      RasterTagMetadata tag = codecs.ReadTag(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1_TAGS.TIF"), 1, 0x8000);
      DisplayTag(tag);
      tag = codecs.ReadTag(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1_TAGS.TIF"), 1, 0x8001);
      DisplayTag(tag);

      codecs.Dispose();
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
function DisplayTag(tag)
{
   switch  (tag.dataType)
   {
      case Leadtools.RasterTagMetadataDataType.ascii:
         console.info("Tag " + tag.id.toString() + " = " + tag.toAscii());
      break;
      
      case Leadtools.RasterTagMetadataDataType.byte:
         console.info("Tag " + tag.id.toString() + " = " + tag.toByte()[0].toString());
      break;
   }
}


RasterImageExamples.prototype.TagsExample = function ( ) 
{
   Tools.SetLicense ( ) ;
   with (Leadtools) {
      with (Leadtools.Codecs) {
         var codecs = new RasterCodecs();
         var srcFileName = "Assets\\Image1.cmp";
         var image;
         return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
            return codecs.loadAsync(LeadStreamFactory.create(loadFile))
         })
               .then(function (img) {
                  image = img;


                  //Ascii
                  var tagDataAscii = new RasterTagMetadata();

                  // set the Copyright tag
                  tagDataAscii.id = 0x8000;
                  tagDataAscii.dataType = RasterTagMetadataDataType.ascii;
                  tagDataAscii.fromAscii("Test String");
                  image.tags.append(tagDataAscii);

                  //Byte
                  var tagDataByte = tagDataAscii.clone();
                  tagDataByte.id = 0x8001;
                  tagDataByte.dataType = RasterTagMetadataDataType.byte;
                  var byteArray = new Array(1);
                  byteArray[0] = 10;
                  tagDataByte.fromByte(byteArray);
                  image.tags.append(tagDataByte);

                  codecs.options.save.tags = true;
                  return Tools.AppLocalFolder().createFileAsync("IMAGE1_TAGS.TIF")
               })
               .then(function (saveFile) {
                  var saveStream = LeadStreamFactory.create(saveFile);
                  return codecs.saveAsync(image, saveStream, RasterImageFormat.tif, 0)})
         .then ( function ( ) {

                  // load the tags together with the image
                  return Tools.AppLocalFolder().getFileAsync("IMAGE1_TAGS.TIF")
               })
               .then(function (loadFile) {
                  return codecs.readTagAsync(LeadStreamFactory.create(loadFile), 1, 0x8000)
               })
               .then(function (tag) {
                  
                  DisplayTag(tag);

                  return Tools.AppLocalFolder().getFileAsync("IMAGE1_TAGS.TIF")
               })
               .then(function (loadFile) {
                  return codecs.readTagAsync(LeadStreamFactory.create(loadFile), 1, 0x8001)
               })
               .then(function (tag) {
                  DisplayTag(tag);
                  codecs.close();
                  image.close();
               });
      }
   }
}
private void DisplayTag(RasterTagMetadata tag)
{
   switch (tag.DataType)
   {
      case RasterTagMetadataDataType.Ascii:
         Debug.WriteLine("Tag " + tag.Id.ToString() + " = " + tag.ToAscii());
         break;
      case RasterTagMetadataDataType.Byte:
         Debug.WriteLine("Tag " + tag.Id.ToString() + " = " + tag.ToByte()[0].ToString());
         break;
   }
}
[TestMethod]
public async Task TagsExample()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = @"Assets\Image1.cmp";
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));

   //Ascii
   RasterTagMetadata tagDataAscii = new RasterTagMetadata();
   // set the Copyright tag
   tagDataAscii.Id = 0x8000;
   tagDataAscii.DataType = RasterTagMetadataDataType.Ascii;
   tagDataAscii.FromAscii("Test String");
   image.Tags.Add(tagDataAscii);

   //Byte
   RasterTagMetadata tagDataByte = tagDataAscii.Clone();
   tagDataByte.Id = 0x8001;
   tagDataByte.DataType = RasterTagMetadataDataType.Byte;
   byte[] byteArray = new byte[1];
   byteArray[0] = 10;
   tagDataByte.FromByte(byteArray);
   image.Tags.Add(tagDataByte);

   codecs.Options.Save.Tags = true;
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync("IMAGE1_TAGS.TIF");
   ILeadStream saveStream = LeadStreamFactory.Create(saveFile);
   await codecs.SaveAsync(image, saveStream, RasterImageFormat.Tif, 0);

   // load the tags together with the image
   loadFile = await Tools.AppLocalFolder.GetFileAsync("IMAGE1_TAGS.TIF");
   RasterTagMetadata tag = await codecs.ReadTagAsync(LeadStreamFactory.Create(loadFile), 1, 0x8000);
   DisplayTag(tag);

   loadFile = await Tools.AppLocalFolder.GetFileAsync("IMAGE1_TAGS.TIF");
   tag = await codecs.ReadTagAsync(LeadStreamFactory.Create(loadFile), 1, 0x8001);
   DisplayTag(tag);

   codecs.Dispose();
}
private void DisplayTag(RasterTagMetadata tag)
{
   switch (tag.DataType)
   {
      case RasterTagMetadataDataType.Ascii:
         Debug.WriteLine("Tag " + tag.Id.ToString() + " = " + tag.ToAscii());
         break;
      case RasterTagMetadataDataType.Byte:
         Debug.WriteLine("Tag " + tag.Id.ToString() + " = " + tag.ToByte()[0].ToString());
         break;
   }
}
public void TagsExample(RasterImage image, Stream destStream)
{
   //Ascii
   RasterTagMetadata tagDataAscii = new RasterTagMetadata();
   // set the Copyright tag
   tagDataAscii.Id = 0x8000;
   tagDataAscii.DataType = RasterTagMetadataDataType.Ascii;
   tagDataAscii.FromAscii("Test String");
   image.Tags.Add(tagDataAscii);
   //Byte
   RasterTagMetadata tagDataByte = tagDataAscii.Clone();
   tagDataAscii.Id = 0x8001;
   tagDataByte.DataType = RasterTagMetadataDataType.Byte;
   byte[] byteArray = new byte[1];
   byteArray[0] = 10;
   tagDataByte.FromByte(byteArray);
   image.Tags.Add(tagDataByte);

   RasterCodecs codecs = new RasterCodecs();
   codecs.Options.Save.Tags = true;
   codecs.Save(image, destStream, RasterImageFormat.Tif, 0);
   // load the tags together with the image

   RasterTagMetadata tag = codecs.ReadTag(destStream, 1, 0x8000);
   DisplayTag(tag);
   tag = codecs.ReadTag(destStream, 1, 0x8001);
   DisplayTag(tag);
}
Private Sub DisplayTag(ByVal tag As RasterTagMetadata)
   Select Case tag.DataType
      Case RasterTagMetadataDataType.Ascii
         Debug.WriteLine("Tag " & tag.Id.ToString() & " = " & tag.ToAscii())
      Case RasterTagMetadataDataType.Byte
         Debug.WriteLine("Tag " & tag.Id.ToString() & " = " & tag.ToByte()(0).ToString())
   End Select
End Sub
Public Sub TagsExample(ByVal image As RasterImage, ByVal destStream As Stream)
   'Ascii
   Dim tagDataAscii As RasterTagMetadata = New RasterTagMetadata()
   ' set the Copyright tag
   tagDataAscii.Id = &H8000
   tagDataAscii.DataType = RasterTagMetadataDataType.Ascii
   tagDataAscii.FromAscii("Test String")
   image.Tags.Add(tagDataAscii)
   'Byte
   Dim tagDataByte As RasterTagMetadata = tagDataAscii.Clone()
   tagDataAscii.Id = &H8001
   tagDataByte.DataType = RasterTagMetadataDataType.Byte
   Dim byteArray As Byte() = New Byte(0){}
   byteArray(0) = 10
   tagDataByte.FromByte(byteArray)
   image.Tags.Add(tagDataByte)

   Dim codecs As RasterCodecs = New RasterCodecs()
   codecs.Options.Save.Tags = True
   codecs.Save(image, destStream, RasterImageFormat.Tif, 0)
   ' load the tags together with the image

   Dim tag As RasterTagMetadata = codecs.ReadTag(destStream, 1, &H8000)
   DisplayTag(tag)
   tag = codecs.ReadTag(destStream, 1, &H8001)
   DisplayTag(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

RasterImage Class
RasterImage Members

 

 


Products | Support | Contact Us | Copyright Notices

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