Gets a comment field from a file.
public RasterCommentMetadata ReadComment(string fileName,int pageNumber,RasterCommentMetadataType type)
Public Overloads Function ReadComment( _ByVal fileName As String, _ByVal pageNumber As Integer, _ByVal type As Leadtools.RasterCommentMetadataType _) As Leadtools.RasterCommentMetadata
public Leadtools.RasterCommentMetadata ReadComment(string fileName,int pageNumber,Leadtools.RasterCommentMetadataType type)
- (nullable LTRasterCommentMetadata *)readCommentFromFile:(NSString *)filepageNumber:(NSInteger)pageNumbertype:(LTRasterCommentMetadataType)typeerror:(NSError **)error
function Leadtools.Codecs.RasterCodecs.ReadComment(String,Int32,RasterCommentMetadataType)(fileName ,pageNumber ,type)
public:Leadtools.RasterCommentMetadata^ ReadComment(String^ fileName,int pageNumber,Leadtools.RasterCommentMetadataType type)
fileName
A String containing the input file name.
pageNumber
1-based index of the page from which to read the comment.
type
The type of comment. Refer to Types of File Comments.
A RasterCommentMetadata object containing the comment field information. If no such comment is found in the file, this method will return a null reference.
Some file formats can contain comments, and some cannot, and each file format has its own set of comment types. When you save a file, the comments in the RasterImage object can be saved in the file. The index into the array (specified using a constant) determines the type of comment.
You can use CommentsSupported to determine whether a certain file format supports tags.
To read all the comments stored in a file, use ReadComments.
This example demonstrates all of the methods related to comments for TIFF files. It saves a few comments to a file before loading them back
using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Color;using Leadtools.Svg;using LeadtoolsExamples.Common;public void CommentsExample(){RasterCodecs codecs = new RasterCodecs();string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_Comments.tif");// Convert the source file to TIFConsole.WriteLine("Converting the source file to TIF");codecs.Convert(srcFileName, destFileName, RasterImageFormat.Tif, 0, 0, 24, null);// Add the artist commentRasterCommentMetadata writeComment = new RasterCommentMetadata();writeComment.Type = RasterCommentMetadataType.Artist;writeComment.FromAscii("LEADTOOLS");Console.WriteLine("Writing the following comment:");Console.WriteLine(" Type:{0}, Data:{1}", writeComment.Type, writeComment.ToAscii());codecs.WriteComment(destFileName, 1, writeComment);// Read the comment backRasterCommentMetadata readComment = codecs.ReadComment(destFileName, 1, RasterCommentMetadataType.Artist);Console.WriteLine("The following comment has been read:");Console.WriteLine(" Type:{0}, Data:{1}", readComment.Type, readComment.ToAscii());// Write a few comments to the file in one passRasterCollection<RasterCommentMetadata> comments = new RasterCollection<RasterCommentMetadata>();writeComment = new RasterCommentMetadata();writeComment.Type = RasterCommentMetadataType.Artist;writeComment.FromAscii("LEADTOOLS Again");comments.Add(writeComment);writeComment = new RasterCommentMetadata();writeComment.Type = RasterCommentMetadataType.Copyright;writeComment.FromAscii("(c) 2006");comments.Add(writeComment);Console.WriteLine("Writing the following comments to the file:");foreach (RasterCommentMetadata comment in comments)Console.WriteLine(" Type:{0}, Data:{1}", comment.Type, comment.ToAscii());codecs.WriteComments(destFileName, 1, comments);// Now get all the comments in the file and show them:Console.WriteLine("Reading all comments from the file:");RasterCommentMetadataType[] tifComments ={RasterCommentMetadataType.Artist,RasterCommentMetadataType.Copyright,RasterCommentMetadataType.DateTime,RasterCommentMetadataType.Description,RasterCommentMetadataType.HostComputer,RasterCommentMetadataType.Make,RasterCommentMetadataType.Model,RasterCommentMetadataType.NameOfDocument,RasterCommentMetadataType.NameOfPage,RasterCommentMetadataType.Software,};foreach (RasterCommentMetadataType tifComment in tifComments){RasterCommentMetadata comment = codecs.ReadComment(destFileName, 1, tifComment);if (comment != null){Console.Write("Found comment, Type:{0}, Data:", comment.Type);RasterCommentMetadataDataType dataType = RasterCommentMetadata.GetDataType(comment.Type);byte[] byteData;short[] shortData;RasterMetadataRational[] rationalData;RasterMetadataURational[] urationalData;switch (dataType){case RasterCommentMetadataDataType.Ascii:Console.WriteLine(comment.ToAscii());break;case RasterCommentMetadataDataType.Byte:byteData = comment.ToByte();for (int i = 0; i < byteData.Length; i++)Console.Write("{0:X} ", byteData[i]);Console.WriteLine();break;case RasterCommentMetadataDataType.Int16:shortData = comment.ToInt16();for (int i = 0; i < shortData.Length; i++)Console.Write("{0:X} ", shortData[i]);Console.WriteLine();break;case RasterCommentMetadataDataType.Rational:rationalData = comment.ToRational();for (int i = 0; i < rationalData.Length; i++)Console.Write(@"{0}/{1) ", rationalData[i].Numerator, rationalData[i].Denominator);Console.WriteLine();break;case RasterCommentMetadataDataType.URational:urationalData = comment.ToURational();for (int i = 0; i < urationalData.Length; i++)Console.Write(@"{0}/{1) ", urationalData[i].Numerator, urationalData[i].Denominator);Console.WriteLine();break;}}}// Clean upcodecs.Dispose();}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.ColorImports Leadtools.DrawingImports Leadtools.SvgPublic Sub CommentsExample()Dim codecs As RasterCodecs = New RasterCodecs()Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_Comments.tif")' Convert the source file to TIFConsole.WriteLine("Converting the source file to TIF")codecs.Convert(srcFileName, destFileName, RasterImageFormat.Tif, 0, 0, 24, Nothing)' Add the artist commentDim writeComment As RasterCommentMetadata = New RasterCommentMetadata()writeComment.Type = RasterCommentMetadataType.ArtistwriteComment.FromAscii("LEADTOOLS")Console.WriteLine("Writing the following comment:")Console.WriteLine(" Type:{0}, Data:{1}", writeComment.Type, writeComment.ToAscii())codecs.WriteComment(destFileName, 1, writeComment)' Read the comment backDim readComment As RasterCommentMetadata = codecs.ReadComment(destFileName, 1, RasterCommentMetadataType.Artist)Console.WriteLine("The following comment has been read:")Console.WriteLine(" Type:{0}, Data:{1}", readComment.Type, readComment.ToAscii())' Write a few comments to the file in one passDim comments As RasterCollection(Of RasterCommentMetadata) = New RasterCollection(Of RasterCommentMetadata)()writeComment = New RasterCommentMetadata()writeComment.Type = RasterCommentMetadataType.ArtistwriteComment.FromAscii("LEADTOOLS Again")comments.Add(writeComment)writeComment = New RasterCommentMetadata()writeComment.Type = RasterCommentMetadataType.CopyrightwriteComment.FromAscii("(c) 2006")comments.Add(writeComment)Console.WriteLine("Writing the following comments to the file:")For Each comment As RasterCommentMetadata In commentsConsole.WriteLine(" Type:{0}, Data:{1}", comment.Type, comment.ToAscii())Next commentcodecs.WriteComments(destFileName, 1, comments)' Now get all the comments in the file and show them:Console.WriteLine("Reading all comments from the file:")Dim tifComments As RasterCommentMetadataType() ={RasterCommentMetadataType.Artist,RasterCommentMetadataType.Copyright,RasterCommentMetadataType.DateTime,RasterCommentMetadataType.Description,RasterCommentMetadataType.HostComputer,RasterCommentMetadataType.Make,RasterCommentMetadataType.Model,RasterCommentMetadataType.NameOfDocument,RasterCommentMetadataType.NameOfPage,RasterCommentMetadataType.Software}For Each tifComment As RasterCommentMetadataType In tifCommentsDim comment As RasterCommentMetadata = codecs.ReadComment(destFileName, 1, tifComment)If Not comment Is Nothing ThenConsole.Write("Found comment, Type:{0}, Data:", comment.Type)Dim dataType As RasterCommentMetadataDataType = RasterCommentMetadata.GetDataType(comment.Type)Dim byteData As Byte()Dim shortData As Short()Dim rationalData As RasterMetadataRational()Dim urationalData As RasterMetadataURational()Select Case dataTypeCase RasterCommentMetadataDataType.AsciiConsole.WriteLine(comment.ToAscii())Case RasterCommentMetadataDataType.BytebyteData = comment.ToByte()Dim i As Integer = 0Do While i < byteData.LengthConsole.Write("{0:X} ", byteData(i))i += 1LoopConsole.WriteLine()Case RasterCommentMetadataDataType.Int16shortData = comment.ToInt16()Dim i As Integer = 0Do While i < shortData.LengthConsole.Write("{0:X} ", shortData(i))i += 1LoopConsole.WriteLine()Case RasterCommentMetadataDataType.RationalrationalData = comment.ToRational()Dim i As Integer = 0Do While i < rationalData.LengthConsole.Write("{0}/{1) ", rationalData(i).Numerator, rationalData(i).Denominator)i += 1LoopConsole.WriteLine()Case RasterCommentMetadataDataType.URationalurationalData = comment.ToURational()Dim i As Integer = 0Do While i < urationalData.LengthConsole.Write("{0}/{1) ", urationalData(i).Numerator, urationalData(i).Denominator)i += 1LoopConsole.WriteLine()End SelectEnd IfNext tifComment' Clean upcodecs.Dispose()End SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
using Leadtools;using Leadtools.Codecs;using Leadtools.Examples;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Color;using Leadtools.Windows.Media;public void CommentsExample(Stream inStreamCmp, Stream outStreamTif){RasterCodecs codecs = new RasterCodecs();// Convert the source file to TIFDebug.WriteLine("Converting the source file to TIF");codecs.Convert(inStreamCmp, outStreamTif, RasterImageFormat.Tif, 0, 0, 24, null);// Add the artist commentRasterCommentMetadata writeComment = new RasterCommentMetadata();writeComment.Type = RasterCommentMetadataType.Artist;writeComment.FromAscii("LEADTOOLS");Debug.WriteLine("Writing the following comment:");Debug.WriteLine(" Type:{0}, Data:{1}", writeComment.Type, writeComment.ToAscii());codecs.WriteComment(outStreamTif, 1, writeComment);// Read the comment backRasterCommentMetadata readComment = codecs.ReadComment(outStreamTif, 1, RasterCommentMetadataType.Artist);Debug.WriteLine("The following comment has been read:");Debug.WriteLine(" Type:{0}, Data:{1}", readComment.Type, readComment.ToAscii());// Write a few comments to the file in one passRasterCollection<RasterCommentMetadata> comments = new RasterCollection<RasterCommentMetadata>();writeComment = new RasterCommentMetadata();writeComment.Type = RasterCommentMetadataType.Artist;writeComment.FromAscii("LEADTOOLS Again");comments.Add(writeComment);writeComment = new RasterCommentMetadata();writeComment.Type = RasterCommentMetadataType.Copyright;writeComment.FromAscii("(c) 2006");comments.Add(writeComment);Debug.WriteLine("Writing the following comments to the file:");foreach (RasterCommentMetadata comment in comments)Debug.WriteLine(" Type:{0}, Data:{1}", comment.Type, comment.ToAscii());codecs.WriteComments(outStreamTif, 1, comments);// Now get all the comments in the file and show them:Debug.WriteLine("Reading all comments from the file:");RasterCommentMetadataType[] tifComments ={RasterCommentMetadataType.Artist,RasterCommentMetadataType.Copyright,RasterCommentMetadataType.DateTime,RasterCommentMetadataType.Description,RasterCommentMetadataType.HostComputer,RasterCommentMetadataType.Make,RasterCommentMetadataType.Model,RasterCommentMetadataType.NameOfDocument,RasterCommentMetadataType.NameOfPage,RasterCommentMetadataType.Software,};foreach (RasterCommentMetadataType tifComment in tifComments){RasterCommentMetadata comment = codecs.ReadComment(outStreamTif, 1, tifComment);if (comment != null){Debug.WriteLine("Found comment, Type:{0}, Data:", comment.Type);RasterCommentMetadataDataType dataType = RasterCommentMetadata.GetDataType(comment.Type);byte[] byteData;short[] shortData;RasterMetadataRational[] rationalData;RasterMetadataURational[] urationalData;switch (dataType){case RasterCommentMetadataDataType.Ascii:Debug.WriteLine(comment.ToAscii());break;case RasterCommentMetadataDataType.Byte:byteData = comment.ToByte();for (int i = 0; i < byteData.Length; i++)Debug.WriteLine("{0:X} ", byteData[i]);Debug.WriteLine("");break;case RasterCommentMetadataDataType.Int16:shortData = comment.ToInt16();for (int i = 0; i < shortData.Length; i++)Debug.WriteLine("{0:X} ", shortData[i]);Debug.WriteLine("");break;case RasterCommentMetadataDataType.Rational:rationalData = comment.ToRational();for (int i = 0; i < rationalData.Length; i++)Debug.WriteLine(@"{0}/{1) ", rationalData[i].Numerator, rationalData[i].Denominator);Debug.WriteLine("");break;case RasterCommentMetadataDataType.URational:urationalData = comment.ToURational();for (int i = 0; i < urationalData.Length; i++)Debug.WriteLine(@"{0}/{1) ", urationalData[i].Numerator, urationalData[i].Denominator);Debug.WriteLine("");break;}}}}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.ColorImports Leadtools.Windows.MediaPublic Sub CommentsExample(ByVal inStreamCmp As Stream, ByVal outStreamTif As Stream)Dim codecs As RasterCodecs = New RasterCodecs()' Convert the source file to TIFDebug.WriteLine("Converting the source file to TIF")codecs.Convert(inStreamCmp, outStreamTif, RasterImageFormat.Tif, 0, 0, 24, Nothing)' Add the artist commentDim writeComment As RasterCommentMetadata = New RasterCommentMetadata()writeComment.Type = RasterCommentMetadataType.ArtistwriteComment.FromAscii("LEADTOOLS")Debug.WriteLine("Writing the following comment:")Debug.WriteLine(" Type:{0}, Data:{1}", writeComment.Type, writeComment.ToAscii())codecs.WriteComment(outStreamTif, 1, writeComment)' Read the comment backDim readComment As RasterCommentMetadata = codecs.ReadComment(outStreamTif, 1, RasterCommentMetadataType.Artist)Debug.WriteLine("The following comment has been read:")Debug.WriteLine(" Type:{0}, Data:{1}", readComment.Type, readComment.ToAscii())' Write a few comments to the file in one passDim comments As RasterCollection(Of RasterCommentMetadata) = New RasterCollection(Of RasterCommentMetadata)()writeComment = New RasterCommentMetadata()writeComment.Type = RasterCommentMetadataType.ArtistwriteComment.FromAscii("LEADTOOLS Again")comments.Add(writeComment)writeComment = New RasterCommentMetadata()writeComment.Type = RasterCommentMetadataType.CopyrightwriteComment.FromAscii("(c) 2006")comments.Add(writeComment)Debug.WriteLine("Writing the following comments to the file:")For Each comment As RasterCommentMetadata In commentsDebug.WriteLine(" Type:{0}, Data:{1}", comment.Type, comment.ToAscii())Next commentcodecs.WriteComments(outStreamTif, 1, comments)' Now get all the comments in the file and show them:Debug.WriteLine("Reading all comments from the file:")Dim tifComments As RasterCommentMetadataType() = {RasterCommentMetadataType.Artist, RasterCommentMetadataType.Copyright, RasterCommentMetadataType.DateTime, RasterCommentMetadataType.Description,RasterCommentMetadataType.HostComputer, RasterCommentMetadataType.Make, RasterCommentMetadataType.Model, RasterCommentMetadataType.NameOfDocument, RasterCommentMetadataType.NameOfPage, RasterCommentMetadataType.Software}For Each tifComment As RasterCommentMetadataType In tifCommentsDim comment As RasterCommentMetadata = codecs.ReadComment(outStreamTif, 1, tifComment)If Not comment Is Nothing ThenDebug.WriteLine("Found comment, Type:{0}, Data:", comment.Type)Dim dataType As RasterCommentMetadataDataType = RasterCommentMetadata.GetDataType(comment.Type)Dim byteData As Byte()Dim shortData As Short()Dim rationalData As RasterMetadataRational()Dim urationalData As RasterMetadataURational()Select Case dataTypeCase RasterCommentMetadataDataType.AsciiDebug.WriteLine(comment.ToAscii())Case RasterCommentMetadataDataType.BytebyteData = comment.ToByte()Dim i As Integer = 0Do While i < byteData.LengthDebug.WriteLine("{0:X} ", byteData(i))i += 1LoopDebug.WriteLine("")Case RasterCommentMetadataDataType.Int16shortData = comment.ToInt16()Dim i As Integer = 0Do While i < shortData.LengthDebug.WriteLine("{0:X} ", shortData(i))i += 1LoopDebug.WriteLine("")Case RasterCommentMetadataDataType.RationalrationalData = comment.ToRational()Dim i As Integer = 0Do While i < rationalData.LengthDebug.WriteLine("{0}/{1) ", rationalData(i).Numerator, rationalData(i).Denominator)i += 1LoopDebug.WriteLine("")Case RasterCommentMetadataDataType.URationalurationalData = comment.ToURational()Dim i As Integer = 0Do While i < urationalData.LengthDebug.WriteLine("{0}/{1) ", urationalData(i).Numerator, urationalData(i).Denominator)i += 1LoopDebug.WriteLine("")End SelectEnd IfNext tifCommentEnd Sub
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
