Leadtools Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
RasterCommentMetadata Class
See Also  Members   Example 
Leadtools Namespace : RasterCommentMetadata Class



Extends the RasterMetadata class to provide functionality for dealing with comment metadata stored within various image file formats.

Syntax

Visual Basic (Declaration) 
<SerializableAttribute()>
Public Class RasterCommentMetadata 
   Inherits RasterMetadata
Visual Basic (Usage)Copy Code
Dim instance As RasterCommentMetadata
C# 
[SerializableAttribute()]
public class RasterCommentMetadata : RasterMetadata 
C++/CLI 
[SerializableAttribute()]
public ref class RasterCommentMetadata : public RasterMetadata 

Example

This example will write comments of different data types to an existing tif file then read them as a test.

Visual BasicCopy Code
Public Sub RasterCommentMetadataExample()
 RasterCodecs.Startup()
 Dim codecs As RasterCodecs = New RasterCodecs()
 codecs.ThrowExceptionsOnInvalidImages = True

 Dim srcFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"
 Dim destFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_comments.tif"

 ' Load the image
 Dim image As RasterImage = codecs.Load(srcFileName)
 codecs.Save(image, destFileName, RasterImageFormat.Tif, 24)

 image.Dispose()

 ' Write some comments to the existing tif file
 Dim comment As RasterCommentMetadata = New RasterCommentMetadata()
 comment.Type = RasterCommentMetadataType.Artist
 Dim artistNameWrite As String = "Artist name"
 comment.FromAscii(artistNameWrite)
 Console.WriteLine("Writing Artist")
 codecs.WriteComment(destFileName, 1, comment)

 comment.Type = RasterCommentMetadataType.GpsLatitude
 Dim rationalsWrite As RasterMetadataRational() = New RasterMetadataRational(2) {}
 Dim i As Integer = 0
 Do While i < rationalsWrite.Length
    rationalsWrite(i) = New RasterMetadataRational(i + 3, i + 2)
    i += 1
 Loop

 comment.FromRational(rationalsWrite)
 Console.WriteLine("Writing GpsLatitude")
 codecs.WriteComment(destFileName, 1, comment)

 ' Now read the comments from the tif file

 ' read ASCII
 comment = codecs.ReadComment(destFileName, 1, RasterCommentMetadataType.Artist)
 Dim artistNameRead As String = comment.ToAscii()
 Console.WriteLine("Artist: {0}", artistNameRead)
 Debug.Assert(artistNameRead = artistNameWrite)

 ' read rationals
 comment = codecs.ReadComment(destFileName, 1, RasterCommentMetadataType.GpsLatitude)
 Dim rationalsRead As RasterMetadataRational() = comment.ToRational()

 Dim size As Integer = rationalsRead.Length
 Console.WriteLine("GpsLatitude: size = {0} ", size)
 i = 0
 Do While i < size
    Console.WriteLine("{0}/{1}", rationalsRead(i).Numerator, rationalsRead(i).Denominator)
    i += 1
 Loop

 Debug.Assert(rationalsRead.Length = rationalsWrite.Length)
 i = 0
 Do While i < rationalsRead.Length
    Debug.Assert(rationalsRead(i).Numerator = rationalsWrite(i).Numerator)
    Debug.Assert(rationalsRead(i).Denominator = rationalsWrite(i).Denominator)
    i += 1
 Loop

 ' Cleanup
 RasterCodecs.Shutdown()
      End Sub
C#Copy Code
public void RasterCommentMetadataExample() 

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.ThrowExceptionsOnInvalidImages = true; 
 
   string srcFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"; 
   string destFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_comments.tif"; 
 
   // Load the image 
   RasterImage image = codecs.Load(srcFileName); 
   codecs.Save(image, destFileName, RasterImageFormat.Tif, 24); 
 
   image.Dispose(); 
 
   // Write some comments to the existing tif file 
   RasterCommentMetadata comment = new RasterCommentMetadata(); 
   comment.Type = RasterCommentMetadataType.Artist; 
   string artistNameWrite = "Artist name"; 
   comment.FromAscii(artistNameWrite); 
   Console.WriteLine("Writing Artist"); 
   codecs.WriteComment(destFileName, 1, comment); 
 
   comment.Type = RasterCommentMetadataType.GpsLatitude; 
   RasterMetadataRational[] rationalsWrite = new RasterMetadataRational[3]; 
   for(int i = 0; i < rationalsWrite.Length; i++) 
      rationalsWrite[i] = new RasterMetadataRational(i + 3, i + 2); 
 
   comment.FromRational(rationalsWrite); 
   Console.WriteLine("Writing GpsLatitude"); 
   codecs.WriteComment(destFileName, 1, comment); 
 
   // Now read the comments from the tif file 
 
   // read ASCII 
   comment = codecs.ReadComment(destFileName, 1, RasterCommentMetadataType.Artist); 
   string artistNameRead = comment.ToAscii(); 
   Console.WriteLine("Artist: {0}", artistNameRead); 
   Debug.Assert(artistNameRead == artistNameWrite); 
 
   // read rationals 
   comment = codecs.ReadComment(destFileName, 1, RasterCommentMetadataType.GpsLatitude); 
   RasterMetadataRational[] rationalsRead = comment.ToRational(); 
 
   int size = rationalsRead.Length; 
   Console.WriteLine("GpsLatitude: size = {0} ", size); 
   for(int i = 0; i < size; i++) 
      Console.WriteLine("{0}/{1}", rationalsRead[i].Numerator, rationalsRead[i].Denominator); 
 
   Debug.Assert(rationalsRead.Length == rationalsWrite.Length); 
   for(int i = 0; i < rationalsRead.Length; i++) 
   { 
      Debug.Assert(rationalsRead[i].Numerator == rationalsWrite[i].Numerator); 
      Debug.Assert(rationalsRead[i].Denominator == rationalsWrite[i].Denominator); 
   } 
 
   // Cleanup 
   RasterCodecs.Shutdown(); 
}

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.

Inheritance Hierarchy

System.Object
   Leadtools.RasterMetadata
      Leadtools.RasterCommentMetadata

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also