Extends the RasterMetadata class to provide functionality for dealing with comment metadata stored within various image file formats.
[SerializableAttribute()]public class RasterCommentMetadata : RasterMetadata
<SerializableAttribute()>Public Class RasterCommentMetadataInherits RasterMetadata
@interface LTRasterCommentMetadata : LTRasterMetadata public class RasterCommentMetadata extends RasterMetadata implements Serializable [SerializableAttribute()]public ref class RasterCommentMetadata : public RasterMetadata
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 [email protected].
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.
This example will write comments of different data types to an existing tif file then read them as a test.
using Leadtools;using Leadtools.Codecs;using LeadtoolsExamples.Common;public void RasterCommentMetadataExample(){RasterCodecs codecs = new RasterCodecs();codecs.ThrowExceptionsOnInvalidImages = true;string srcFileName = Path.Combine(ImagesPath.Path, "Image1.cmp");string destFileName = Path.Combine(ImagesPath.Path, "Image1_comments.tif");// Load the imageRasterImage image = codecs.Load(srcFileName);codecs.Save(image, destFileName, RasterImageFormat.Tif, 24);image.Dispose();// Write some comments to the existing tif fileRasterCommentMetadata 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 ASCIIcomment = codecs.ReadComment(destFileName, 1, RasterCommentMetadataType.Artist);string artistNameRead = comment.ToAscii();Console.WriteLine("Artist: {0}", artistNameRead);Assert.IsTrue(artistNameRead == artistNameWrite);// read rationalscomment = 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);Assert.IsTrue(rationalsRead.Length == rationalsWrite.Length);for (int i = 0; i < rationalsRead.Length; i++){Assert.IsTrue(rationalsRead[i].Numerator == rationalsWrite[i].Numerator);Assert.IsTrue(rationalsRead[i].Denominator == rationalsWrite[i].Denominator);}}
Imports LeadtoolsImports Leadtools.CodecsPublic Sub RasterCommentMetadataExample()Dim codecs As RasterCodecs = New RasterCodecs()codecs.ThrowExceptionsOnInvalidImages = TrueDim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_comments.tif")' Load the imageDim image As RasterImage = codecs.Load(srcFileName)codecs.Save(image, destFileName, RasterImageFormat.Tif, 24)image.Dispose()' Write some comments to the existing tif fileDim comment As RasterCommentMetadata = New RasterCommentMetadata()comment.Type = RasterCommentMetadataType.ArtistDim artistNameWrite As String = "Artist name"comment.FromAscii(artistNameWrite)Console.WriteLine("Writing Artist")codecs.WriteComment(destFileName, 1, comment)comment.Type = RasterCommentMetadataType.GpsLatitudeDim rationalsWrite As RasterMetadataRational() = New RasterMetadataRational(2) {}Dim i As Integer = 0Do While i < rationalsWrite.LengthrationalsWrite(i) = New RasterMetadataRational(i + 3, i + 2)i += 1Loopcomment.FromRational(rationalsWrite)Console.WriteLine("Writing GpsLatitude")codecs.WriteComment(destFileName, 1, comment)' Now read the comments from the tif file' read ASCIIcomment = codecs.ReadComment(destFileName, 1, RasterCommentMetadataType.Artist)Dim artistNameRead As String = comment.ToAscii()Console.WriteLine("Artist: {0}", artistNameRead)Debug.Assert(artistNameRead = artistNameWrite)' read rationalscomment = codecs.ReadComment(destFileName, 1, RasterCommentMetadataType.GpsLatitude)Dim rationalsRead As RasterMetadataRational() = comment.ToRational()Dim size As Integer = rationalsRead.LengthConsole.WriteLine("GpsLatitude: size = {0} ", size)i = 0Do While i < sizeConsole.WriteLine("{0}/{1}", rationalsRead(i).Numerator, rationalsRead(i).Denominator)i += 1LoopDebug.Assert(rationalsRead.Length = rationalsWrite.Length)i = 0Do While i < rationalsRead.LengthDebug.Assert(rationalsRead(i).Numerator = rationalsWrite(i).Numerator)Debug.Assert(rationalsRead(i).Denominator = rationalsWrite(i).Denominator)i += 1LoopEnd SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
c#[Silverlight C# Example]using Leadtools;using Leadtools.Codecs;using Leadtools.Examples;using Leadtools.ImageProcessing;public void RasterCommentMetadataExample(RasterImage image, Stream destStream){RasterCodecs codecs = new RasterCodecs();codecs.Save(image, destStream, RasterImageFormat.Tif, 24);image.Dispose();// Write some comments to the existing tif fileRasterCommentMetadata comment = new RasterCommentMetadata();comment.Type = RasterCommentMetadataType.Artist;string artistNameWrite = "Artist name";comment.FromAscii(artistNameWrite);Debug.WriteLine("Writing Artist");codecs.WriteComment(destStream, 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);Debug.WriteLine("Writing GpsLatitude");codecs.WriteComment(destStream, 1, comment);// Now read the comments from the tif file// read ASCIIcomment = codecs.ReadComment(destStream, 1, RasterCommentMetadataType.Artist);string artistNameRead = comment.ToAscii();Debug.WriteLine("Artist: {0}", artistNameRead);Debug.Assert(artistNameRead == artistNameWrite);// read rationalscomment = codecs.ReadComment(destStream, 1, RasterCommentMetadataType.GpsLatitude);RasterMetadataRational[] rationalsRead = comment.ToRational();int size = rationalsRead.Length;Debug.WriteLine("GpsLatitude: size = {0} ", size);for (int i = 0; i < size; i++)Debug.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);}}vb[Silverlight VB Example]Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessingPublic Sub RasterCommentMetadataExample(ByVal image As RasterImage, ByVal destStream As Stream)Dim codecs As RasterCodecs = New RasterCodecs()codecs.Save(image, destStream, RasterImageFormat.Tif, 24)image.Dispose()' Write some comments to the existing tif fileDim comment As RasterCommentMetadata = New RasterCommentMetadata()comment.Type = RasterCommentMetadataType.ArtistDim artistNameWrite As String = "Artist name"comment.FromAscii(artistNameWrite)Debug.WriteLine("Writing Artist")codecs.WriteComment(destStream, 1, comment)comment.Type = RasterCommentMetadataType.GpsLatitudeDim rationalsWrite As RasterMetadataRational() = New RasterMetadataRational(2) {}Dim i As Integer = 0Do While i < rationalsWrite.LengthrationalsWrite(i) = New RasterMetadataRational(i + 3, i + 2)i += 1Loopcomment.FromRational(rationalsWrite)Debug.WriteLine("Writing GpsLatitude")codecs.WriteComment(destStream, 1, comment)' Now read the comments from the tif file' read ASCIIcomment = codecs.ReadComment(destStream, 1, RasterCommentMetadataType.Artist)Dim artistNameRead As String = comment.ToAscii()Debug.WriteLine("Artist: {0}", artistNameRead)Debug.Assert(artistNameRead = artistNameWrite)' read rationalscomment = codecs.ReadComment(destStream, 1, RasterCommentMetadataType.GpsLatitude)Dim rationalsRead As RasterMetadataRational() = comment.ToRational()Dim size As Integer = rationalsRead.LengthDebug.WriteLine("GpsLatitude: size = {0} ", size)i = 0Do While i < sizeDebug.WriteLine("{0}/{1}", rationalsRead(i).Numerator, rationalsRead(i).Denominator)i += 1LoopDebug.Assert(rationalsRead.Length = rationalsWrite.Length)i = 0Do While i < rationalsRead.LengthDebug.Assert(rationalsRead(i).Numerator = rationalsWrite(i).Numerator)Debug.Assert(rationalsRead(i).Denominator = rationalsWrite(i).Denominator)i += 1LoopEnd Sub
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
