LEADTOOLS (Leadtools assembly)
LEAD Technologies, Inc

RasterTagMetadata Class

Example 





Members 
Extends the RasterMetadata class to provide functionality for dealing with tag metadata stored within various image file formats. .NET support Silverlight support WinRT support
Object Model
RasterTagMetadata Class
Syntax
[SerializableAttribute()]
public class RasterTagMetadata : RasterMetadata 
'Declaration
 
<SerializableAttribute()>
Public Class RasterTagMetadata 
   Inherits RasterMetadata
'Usage
 
Dim instance As RasterTagMetadata
public sealed class RasterTagMetadata : RasterMetadata 
function Leadtools.RasterTagMetadata()
[SerializableAttribute()]
public ref class RasterTagMetadata : public RasterMetadata 
Remarks

The TIFF file formats support a number of comments that are saved and loaded using predefined tags.

If the comments do not meet your needs, you can define your own tag for saving additional non-raster data in a TIFF file. For example, you may want to define a tag to save annotations.

The TIFF 6.0 Specification sets aside a range of private tags that developers can define. To avoid conflicts with files created by other developers, you can register your tag by contacting Adobe Developer Relations. The E-Mail address posted on The Unofficial TIFF Home Page is gapdevsup@adobe.com.

Some restrictions apply to this function if you use an IFD to indicate to which page to write the metadata. See the Loading And Saving Large TIFF Files topic for more information.

Example
 
Public Sub RasterTagMetadataExample()
      Dim codecs As RasterCodecs = New RasterCodecs()
      codecs.ThrowExceptionsOnInvalidImages = True

      Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")
      Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_tags.tif")

      ' Load the image
      Dim image As RasterImage = codecs.Load(srcFileName)

      ' add the tags
      Const tagSoftware As Integer = &H131

      Dim tag As RasterTagMetadata

      ' Ascii
      tag = New RasterTagMetadata()
      tag.Id = tagSoftware
      tag.DataType = RasterTagMetadataDataType.Ascii
      tag.FromAscii("Test String")
      image.Tags.Add(tag)

      ' Byte
      tag = New RasterTagMetadata()
      tag.Id = tagSoftware
      tag.DataType = RasterTagMetadataDataType.Byte
      Dim byteArray As Byte() = New Byte(0) {}
      byteArray(0) = 10
      tag.FromByte(byteArray)
      image.Tags.Add(tag)

      ' SByte
      tag = New RasterTagMetadata()
      tag.Id = tagSoftware
      tag.DataType = RasterTagMetadataDataType.SByte
      Dim sbyteArray As SByte() = New SByte(0) {}
      sbyteArray(0) = -45
      tag.FromSByte(sbyteArray)
      image.Tags.Add(tag)

      ' Int16
      tag = New RasterTagMetadata()
      tag.Id = tagSoftware
      tag.DataType = RasterTagMetadataDataType.Int16
      Dim shortArray As Short() = New Short(0) {}
      shortArray(0) = 64
      tag.FromInt16(shortArray)
      image.Tags.Add(tag)

      ' Uint16
      tag = New RasterTagMetadata()
      tag.Id = tagSoftware
      tag.DataType = RasterTagMetadataDataType.UInt16
      Dim uint16Array As System.UInt16() = New System.UInt16(0) {}
      uint16Array(0) = 50
      tag.FromUInt16(uint16Array)
      image.Tags.Add(tag)

      ' Int32
      tag = New RasterTagMetadata()
      tag.Id = tagSoftware
      tag.DataType = RasterTagMetadataDataType.Int32
      Dim intArray As Integer() = New Integer(0) {}
      intArray(0) = -1326
      tag.FromInt32(intArray)
      image.Tags.Add(tag)

      ' Uint32
      tag = New RasterTagMetadata()
      tag.Id = tagSoftware
      tag.DataType = RasterTagMetadataDataType.UInt32
      Dim uintArray As System.UInt32() = New System.UInt32(0) {}
      uintArray(0) = 1326
      tag.FromUInt32(uintArray)
      image.Tags.Add(tag)

      ' single
      tag = New RasterTagMetadata()
      tag.Id = tagSoftware
      tag.DataType = RasterTagMetadataDataType.Single
      Dim singleArray As Single() = New Single(0) {}
      singleArray(0) = 4.53F
      tag.FromSingle(singleArray)
      image.Tags.Add(tag)

      ' Double
      tag = New RasterTagMetadata()
      tag.Id = tagSoftware
      tag.DataType = RasterTagMetadataDataType.Double
      Dim doubleArray As Double() = New Double(0) {}
      doubleArray(0) = 7.1
      tag.FromDouble(doubleArray)
      image.Tags.Add(tag)

      ' Rational
      tag = New RasterTagMetadata()
      tag.Id = tagSoftware
      tag.DataType = RasterTagMetadataDataType.Rational
      Dim rational As RasterMetadataRational() = New RasterMetadataRational(0) {}
      rational(0) = New RasterMetadataRational()
      rational(0).Numerator = 3
      rational(0).Denominator = 2
      tag.FromRational(rational)
      image.Tags.Add(tag)

      ' URational
      tag = New RasterTagMetadata()
      tag.Id = tagSoftware
      tag.DataType = RasterTagMetadataDataType.URational
      Dim urational As RasterMetadataURational() = New RasterMetadataURational(0) {}
      urational(0) = New RasterMetadataURational(3, 2)
      tag.FromURational(urational)
      image.Tags.Add(tag)

      ' Save the image and its tags to the destination tiff file
      codecs.Options.Save.Tags = True
      codecs.Save(image, destFileName, RasterImageFormat.Tif, 1)

      ' Enumerate the tags from the file
      AddHandler codecs.TagFound, AddressOf codecs_TagFound
      codecs.EnumTags(destFileName, 1)

      ' clean up
      image.Dispose()
   End Sub

   Private Sub codecs_TagFound(ByVal sender As Object, ByVal e As CodecsEnumTagsEventArgs)
      Console.WriteLine("Found tag id = {0}, count = {1}, type = {2}", e.Id, e.Count, e.MetadataType)
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void RasterTagMetadataExample()
   {
      RasterCodecs codecs = new RasterCodecs();
      codecs.ThrowExceptionsOnInvalidImages = true;

      string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");
      string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_tags.tif");

      // Load the image
      RasterImage image = codecs.Load(srcFileName);

      // add the tags
      const int tagSoftware = 0x131;

      RasterTagMetadata tag;

      // Ascii
      tag = new RasterTagMetadata();
      tag.Id = tagSoftware;
      tag.DataType = RasterTagMetadataDataType.Ascii;
      tag.FromAscii("Test String");
      image.Tags.Add(tag);

      // Byte
      tag = new RasterTagMetadata();
      tag.Id = tagSoftware;
      tag.DataType = RasterTagMetadataDataType.Byte;
      byte[] byteArray = new byte[1];
      byteArray[0] = 10;
      tag.FromByte(byteArray);
      image.Tags.Add(tag);

      // SByte
      tag = new RasterTagMetadata();
      tag.Id = tagSoftware;
      tag.DataType = RasterTagMetadataDataType.SByte;
      sbyte[] sbyteArray = new sbyte[1];
      sbyteArray[0] = -45;
      tag.FromSByte(sbyteArray);
      image.Tags.Add(tag);

      // Int16
      tag = new RasterTagMetadata();
      tag.Id = tagSoftware;
      tag.DataType = RasterTagMetadataDataType.Int16;
      short[] shortArray = new short[1];
      shortArray[0] = 64;
      tag.FromInt16(shortArray);
      image.Tags.Add(tag);

      // Uint16
      tag = new RasterTagMetadata();
      tag.Id = tagSoftware;
      tag.DataType = RasterTagMetadataDataType.UInt16;
      ushort[] uint16Array = new ushort[1];
      uint16Array[0] = 50;
      tag.FromUInt16(uint16Array);
      image.Tags.Add(tag);

      // Int32
      tag = new RasterTagMetadata();
      tag.Id = tagSoftware;
      tag.DataType = RasterTagMetadataDataType.Int32;
      int[] intArray = new int[1];
      intArray[0] = -1326;
      tag.FromInt32(intArray);
      image.Tags.Add(tag);

      // Uint32
      tag = new RasterTagMetadata();
      tag.Id = tagSoftware;
      tag.DataType = RasterTagMetadataDataType.UInt32;
      uint[] uintArray = new uint[1];
      uintArray[0] = 1326;
      tag.FromUInt32(uintArray);
      image.Tags.Add(tag);

      // single
      tag = new RasterTagMetadata();
      tag.Id = tagSoftware;
      tag.DataType = RasterTagMetadataDataType.Single;
      float[] singleArray = new float[1];
      singleArray[0] = 4.53f;
      tag.FromSingle(singleArray);
      image.Tags.Add(tag);

      // Double
      tag = new RasterTagMetadata();
      tag.Id = tagSoftware;
      tag.DataType = RasterTagMetadataDataType.Double;
      double[] doubleArray = new double[1];
      doubleArray[0] = 7.1;
      tag.FromDouble(doubleArray);
      image.Tags.Add(tag);

      // Rational
      tag = new RasterTagMetadata();
      tag.Id = tagSoftware;
      tag.DataType = RasterTagMetadataDataType.Rational;
      RasterMetadataRational[] rational = new RasterMetadataRational[1];
      rational[0] = new RasterMetadataRational();
      rational[0].Numerator = 3;
      rational[0].Denominator = 2;
      tag.FromRational(rational);
      image.Tags.Add(tag);

      // URational
      tag = new RasterTagMetadata();
      tag.Id = tagSoftware;
      tag.DataType = RasterTagMetadataDataType.URational;
      RasterMetadataURational[] urational = new RasterMetadataURational[1];
      urational[0] = new RasterMetadataURational(3, 2);
      tag.FromURational(urational);
      image.Tags.Add(tag);

      // Save the image and its tags to the destination tiff file
      codecs.Options.Save.Tags = true;
      codecs.Save(image, destFileName, RasterImageFormat.Tif, 1);

      // Enumerate the tags from the file
      codecs.TagFound += new EventHandler<CodecsEnumTagsEventArgs>(codecs_TagFound);
      codecs.EnumTags(destFileName, 1);

      // clean up
      image.Dispose();
   }

   void codecs_TagFound(object sender, CodecsEnumTagsEventArgs e)
   {
      Console.WriteLine("Found tag id = {0}, count = {1}, type = {2}", e.Id, e.Count, e.MetadataType);
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
RasterTagMetadataExamples.prototype.RasterTagMetadataExample = function () {
    Tools.SetLicense();
    with (Leadtools) {
        with (Leadtools.Codecs) {
            var codecs = new RasterCodecs();
            codecs.throwExceptionsOnInvalidImages = true;

            var srcFileName = "Assets\\Image1.cmp";
            var destFileName = "Image1_tags.tif";
            var image;

            var saveFile;
            // Load the image
            return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
                return codecs.loadAsync(LeadStreamFactory.create(loadFile))
            })
                .then(function (img) {
                    image = img;

                    // add the tags
                    var tagSoftware = 0x131;

                    var tag;

                    // Ascii
                    tag = new RasterTagMetadata();
                    tag.id = tagSoftware;
                    tag.dataType = RasterTagMetadataDataType.ascii;
                    tag.fromAscii("Test String");
                    image.tags.append(tag);

                    // Byte
                    tag = new RasterTagMetadata();
                    tag.id = tagSoftware;
                    tag.dataType = RasterTagMetadataDataType.byte;
                    var byteArray = [10];
                    tag.fromByte(byteArray);
                    image.tags.append(tag);

                    // Int16
                    tag = new RasterTagMetadata();
                    tag.id = tagSoftware;
                    tag.dataType = RasterTagMetadataDataType.int16;
                    var shortArray = [64];
                    tag.fromInt16(shortArray);
                    image.tags.append(tag);

                    // Uint16
                    tag = new RasterTagMetadata();
                    tag.id = tagSoftware;
                    tag.dataType = RasterTagMetadataDataType.uint16;
                    var uint16Array = [50];
                    tag.fromUInt16(uint16Array);
                    image.tags.append(tag);

                    // Int32
                    tag = new RasterTagMetadata();
                    tag.id = tagSoftware;
                    tag.dataType = RasterTagMetadataDataType.int32;
                    var intArray = [-1326];
                    tag.fromInt32(intArray);
                    image.tags.append(tag);

                    // Uint32
                    tag = new RasterTagMetadata();
                    tag.id = tagSoftware;
                    tag.dataType = RasterTagMetadataDataType.uint32;
                    var uintArray = [1326];
                    tag.fromUInt32(uintArray);
                    image.tags.append(tag);

                    // single
                    tag = new RasterTagMetadata();
                    tag.id = tagSoftware;
                    tag.dataType = RasterTagMetadataDataType.single;
                    var singleArray = [4.53];
                    tag.fromSingle(singleArray);
                    image.tags.append(tag);

                    // Double
                    tag = new RasterTagMetadata();
                    tag.id = tagSoftware;
                    tag.dataType = RasterTagMetadataDataType.double;
                    var doubleArray = [7.1];
                    tag.fromDouble(doubleArray);
                    image.tags.append(tag);

                    // Rational
                    tag = new RasterTagMetadata();
                    tag.id = tagSoftware;
                    tag.dataType = RasterTagMetadataDataType.rational;
                    var rational = [];

                    rational[0] = {};
                    rational[0].numerator = 3;
                    rational[0].denominator = 2;
                    tag.fromRational(rational);
                    image.tags.append(tag);

                    // URational
                    tag = new RasterTagMetadata();
                    tag.id = tagSoftware;
                    tag.dataType = RasterTagMetadataDataType.urational;
                    var urational = [];
                    urational[0] = RasterMetadataURationalHelper.create(3, 2);
                    tag.fromURational(urational);
                    image.tags.append(tag);

                    // Save the image and its tags to the destination tiff file
                    codecs.options.save.tags = true;
                    return Tools.AppLocalFolder().createFileAsync(destFileName)
                })
                .then(function (sFile) {
                    saveFile = sFile;
                    return codecs.saveAsync(image, LeadStreamFactory.create(saveFile), RasterImageFormat.tif, 1)
                })
                .then(function () {
                    // Enumerate the tags from the file
                    codecs.addEventListener("tagFound", codecs_TagFound);
                    return codecs.enumTagsAsync(LeadStreamFactory.create(saveFile), 1)
                })
                .then(function () {

                    // clean up
                    image.close();
                });
        }
    }
}

function codecs_TagFound(e)
{
    console.info("Found tag id = " + e.id + ", count = " + e.count + ", type = " + e.metadataType);
}
[TestMethod]
public async Task RasterTagMetadataExample()
{
   RasterCodecs codecs = new RasterCodecs();
   codecs.ThrowExceptionsOnInvalidImages = true;
   string srcFileName = @"Assets\Image1.cmp";
   string destFileName = @"Image1_tags.tif";

   // Load the image
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));

   // add the tags
   const int tagSoftware = 0x131;

   RasterTagMetadata tag;

   // Ascii
   tag = new RasterTagMetadata();
   tag.Id = tagSoftware;
   tag.DataType = RasterTagMetadataDataType.Ascii;
   tag.FromAscii("Test String");
   image.Tags.Add(tag);

   // Byte
   tag = new RasterTagMetadata();
   tag.Id = tagSoftware;
   tag.DataType = RasterTagMetadataDataType.Byte;
   byte[] byteArray = new byte[1];
   byteArray[0] = 10;
   tag.FromByte(byteArray);
   image.Tags.Add(tag);

   // Int16
   tag = new RasterTagMetadata();
   tag.Id = tagSoftware;
   tag.DataType = RasterTagMetadataDataType.Int16;
   short[] shortArray = new short[1];
   shortArray[0] = 64;
   tag.FromInt16(shortArray);
   image.Tags.Add(tag);

   // Uint16
   tag = new RasterTagMetadata();
   tag.Id = tagSoftware;
   tag.DataType = RasterTagMetadataDataType.UInt16;
   ushort[] uint16Array = new ushort[1];
   uint16Array[0] = 50;
   tag.FromUInt16(uint16Array);
   image.Tags.Add(tag);

   // Int32
   tag = new RasterTagMetadata();
   tag.Id = tagSoftware;
   tag.DataType = RasterTagMetadataDataType.Int32;
   int[] intArray = new int[1];
   intArray[0] = -1326;
   tag.FromInt32(intArray);
   image.Tags.Add(tag);

   // Uint32
   tag = new RasterTagMetadata();
   tag.Id = tagSoftware;
   tag.DataType = RasterTagMetadataDataType.UInt32;
   uint[] uintArray = new uint[1];
   uintArray[0] = 1326;
   tag.FromUInt32(uintArray);
   image.Tags.Add(tag);

   // single
   tag = new RasterTagMetadata();
   tag.Id = tagSoftware;
   tag.DataType = RasterTagMetadataDataType.Single;
   float[] singleArray = new float[1];
   singleArray[0] = 4.53f;
   tag.FromSingle(singleArray);
   image.Tags.Add(tag);

   // Double
   tag = new RasterTagMetadata();
   tag.Id = tagSoftware;
   tag.DataType = RasterTagMetadataDataType.Double;
   double[] doubleArray = new double[1];
   doubleArray[0] = 7.1;
   tag.FromDouble(doubleArray);
   image.Tags.Add(tag);

   // Rational
   tag = new RasterTagMetadata();
   tag.Id = tagSoftware;
   tag.DataType = RasterTagMetadataDataType.Rational;
   RasterMetadataRational[] rational = new RasterMetadataRational[1];
   rational[0] = new RasterMetadataRational();
   rational[0].Numerator = 3;
   rational[0].Denominator = 2;
   tag.FromRational(rational);
   image.Tags.Add(tag);

   // URational
   tag = new RasterTagMetadata();
   tag.Id = tagSoftware;
   tag.DataType = RasterTagMetadataDataType.URational;
   RasterMetadataURational[] urational = new RasterMetadataURational[1];
   urational[0] = RasterMetadataURationalHelper.Create(3, 2);
   tag.FromURational(urational);
   image.Tags.Add(tag);

   // Save the image and its tags to the destination tiff file
   codecs.Options.Save.Tags = true;
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Tif, 1);

   // Enumerate the tags from the file
   codecs.TagFound += new EventHandler<CodecsEnumTagsEventArgs>(codecs_TagFound);
   await codecs.EnumTagsAsync(LeadStreamFactory.Create(saveFile), 1);

   // clean up
   image.Dispose();
}

void codecs_TagFound(object sender, CodecsEnumTagsEventArgs e)
{
   Debug.WriteLine("Found tag id = {0}, count = {1}, type = {2}", e.Id, e.Count, e.MetadataType);
}
public void RasterTagMetadataExample(RasterImage image, Stream destStream)
{
   RasterCodecs codecs = new RasterCodecs();
   // add the tags
   const int tagSoftware = 0x131;

   RasterTagMetadata tag;

   // Ascii
   tag = new RasterTagMetadata();
   tag.Id = tagSoftware;
   tag.DataType = RasterTagMetadataDataType.Ascii;
   tag.FromAscii("Test String");
   image.Tags.Add(tag);

   // Byte
   tag = new RasterTagMetadata();
   tag.Id = tagSoftware;
   tag.DataType = RasterTagMetadataDataType.Byte;
   byte[] byteArray = new byte[1];
   byteArray[0] = 10;
   tag.FromByte(byteArray);
   image.Tags.Add(tag);

   // SByte
   tag = new RasterTagMetadata();
   tag.Id = tagSoftware;
   tag.DataType = RasterTagMetadataDataType.SByte;
   sbyte[] sbyteArray = new sbyte[1];
   sbyteArray[0] = -45;
   tag.FromSByte(sbyteArray);
   image.Tags.Add(tag);

   // Int16
   tag = new RasterTagMetadata();
   tag.Id = tagSoftware;
   tag.DataType = RasterTagMetadataDataType.Int16;
   short[] shortArray = new short[1];
   shortArray[0] = 64;
   tag.FromInt16(shortArray);
   image.Tags.Add(tag);

   // Uint16
   tag = new RasterTagMetadata();
   tag.Id = tagSoftware;
   tag.DataType = RasterTagMetadataDataType.UInt16;
   ushort[] uint16Array = new ushort[1];
   uint16Array[0] = 50;
   tag.FromUInt16(uint16Array);
   image.Tags.Add(tag);

   // Int32
   tag = new RasterTagMetadata();
   tag.Id = tagSoftware;
   tag.DataType = RasterTagMetadataDataType.Int32;
   int[] intArray = new int[1];
   intArray[0] = -1326;
   tag.FromInt32(intArray);
   image.Tags.Add(tag);

   // Uint32
   tag = new RasterTagMetadata();
   tag.Id = tagSoftware;
   tag.DataType = RasterTagMetadataDataType.UInt32;
   uint[] uintArray = new uint[1];
   uintArray[0] = 1326;
   tag.FromUInt32(uintArray);
   image.Tags.Add(tag);

   // single
   tag = new RasterTagMetadata();
   tag.Id = tagSoftware;
   tag.DataType = RasterTagMetadataDataType.Single;
   float[] singleArray = new float[1];
   singleArray[0] = 4.53f;
   tag.FromSingle(singleArray);
   image.Tags.Add(tag);

   // Double
   tag = new RasterTagMetadata();
   tag.Id = tagSoftware;
   tag.DataType = RasterTagMetadataDataType.Double;
   double[] doubleArray = new double[1];
   doubleArray[0] = 7.1;
   tag.FromDouble(doubleArray);
   image.Tags.Add(tag);

   // Rational
   tag = new RasterTagMetadata();
   tag.Id = tagSoftware;
   tag.DataType = RasterTagMetadataDataType.Rational;
   RasterMetadataRational[] rational = new RasterMetadataRational[1];
   rational[0] = new RasterMetadataRational();
   rational[0].Numerator = 3;
   rational[0].Denominator = 2;
   tag.FromRational(rational);
   image.Tags.Add(tag);

   // URational
   tag = new RasterTagMetadata();
   tag.Id = tagSoftware;
   tag.DataType = RasterTagMetadataDataType.URational;
   RasterMetadataURational[] urational = new RasterMetadataURational[1];
   urational[0] = new RasterMetadataURational(3, 2);
   tag.FromURational(urational);
   image.Tags.Add(tag);

   // Save the image and its tags to the destination tiff file
   codecs.Options.Save.Tags = true;
   codecs.Save(image, destStream, RasterImageFormat.Tif, 1);

   // Enumerate the tags from the file
   codecs.TagFound += new EventHandler<CodecsEnumTagsEventArgs>(codecs_TagFound);
   codecs.EnumTags(destStream, 1);

   // clean up
   image.Dispose();
}

void codecs_TagFound(object sender, CodecsEnumTagsEventArgs e)
{
   Debug.WriteLine("Found tag id = {0}, count = {1}, type = {2}", e.Id, e.Count, e.MetadataType);
}
Public Sub RasterTagMetadataExample(ByVal image As RasterImage, ByVal destStream As Stream)
   Dim codecs As RasterCodecs = New RasterCodecs()
   ' add the tags
   Const tagSoftware As Integer = &H131

   Dim tag As RasterTagMetadata

   ' Ascii
   tag = New RasterTagMetadata()
   tag.Id = tagSoftware
   tag.DataType = RasterTagMetadataDataType.Ascii
   tag.FromAscii("Test String")
   image.Tags.Add(tag)

   ' Byte
   tag = New RasterTagMetadata()
   tag.Id = tagSoftware
   tag.DataType = RasterTagMetadataDataType.Byte
   Dim byteArray As Byte() = New Byte(0){}
   byteArray(0) = 10
   tag.FromByte(byteArray)
   image.Tags.Add(tag)

   ' SByte
   tag = New RasterTagMetadata()
   tag.Id = tagSoftware
   tag.DataType = RasterTagMetadataDataType.SByte
   Dim sbyteArray As SByte() = New SByte(0){}
   sbyteArray(0) = -45
   tag.FromSByte(sbyteArray)
   image.Tags.Add(tag)

   ' Int16
   tag = New RasterTagMetadata()
   tag.Id = tagSoftware
   tag.DataType = RasterTagMetadataDataType.Int16
   Dim shortArray As Short() = New Short(0){}
   shortArray(0) = 64
   tag.FromInt16(shortArray)
   image.Tags.Add(tag)

   ' Uint16
   tag = New RasterTagMetadata()
   tag.Id = tagSoftware
   tag.DataType = RasterTagMetadataDataType.UInt16
   Dim uint16Array As UShort() = New UShort(0){}
   uint16Array(0) = 50
   tag.FromUInt16(uint16Array)
   image.Tags.Add(tag)

   ' Int32
   tag = New RasterTagMetadata()
   tag.Id = tagSoftware
   tag.DataType = RasterTagMetadataDataType.Int32
   Dim intArray As Integer() = New Integer(0){}
   intArray(0) = -1326
   tag.FromInt32(intArray)
   image.Tags.Add(tag)

   ' Uint32
   tag = New RasterTagMetadata()
   tag.Id = tagSoftware
   tag.DataType = RasterTagMetadataDataType.UInt32
   Dim uintArray As UInteger() = New UInteger(0){}
   uintArray(0) = 1326
   tag.FromUInt32(uintArray)
   image.Tags.Add(tag)

   ' single
   tag = New RasterTagMetadata()
   tag.Id = tagSoftware
   tag.DataType = RasterTagMetadataDataType.Single
   Dim singleArray As Single() = New Single(0){}
   singleArray(0) = 4.53f
   tag.FromSingle(singleArray)
   image.Tags.Add(tag)

   ' Double
   tag = New RasterTagMetadata()
   tag.Id = tagSoftware
   tag.DataType = RasterTagMetadataDataType.Double
   Dim doubleArray As Double() = New Double(0){}
   doubleArray(0) = 7.1
   tag.FromDouble(doubleArray)
   image.Tags.Add(tag)

   ' Rational
   tag = New RasterTagMetadata()
   tag.Id = tagSoftware
   tag.DataType = RasterTagMetadataDataType.Rational
   Dim rational As RasterMetadataRational() = New RasterMetadataRational(0){}
   rational(0) = New RasterMetadataRational()
   rational(0).Numerator = 3
   rational(0).Denominator = 2
   tag.FromRational(rational)
   image.Tags.Add(tag)

   ' URational
   tag = New RasterTagMetadata()
   tag.Id = tagSoftware
   tag.DataType = RasterTagMetadataDataType.URational
   Dim urational As RasterMetadataURational() = New RasterMetadataURational(0){}
   urational(0) = New RasterMetadataURational(3, 2)
   tag.FromURational(urational)
   image.Tags.Add(tag)

   ' Save the image and its tags to the destination tiff file
   codecs.Options.Save.Tags = True
   codecs.Save(image, destStream, RasterImageFormat.Tif, 1)

   ' Enumerate the tags from the file
   AddHandler codecs.TagFound, AddressOf codecs_TagFound
   codecs.EnumTags(destStream, 1)

   ' clean up
   image.Dispose()
End Sub

Private Sub codecs_TagFound(ByVal sender As Object, ByVal e As CodecsEnumTagsEventArgs)
   Debug.WriteLine("Found tag id = {0}, count = {1}, type = {2}", e.Id, e.Count, e.MetadataType)
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

RasterTagMetadata Members
Leadtools Namespace

 

 


Products | Support | Contact Us | Copyright Notices

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