public RasterCommentMetadata ReadComment(Stream stream,int pageNumber,RasterCommentMetadataType type)
- (nullable LTRasterCommentMetadata *)readCommentFromStream:(LTLeadStream *)streampageNumber:(NSInteger)pageNumbertype:(LTRasterCommentMetadataType)typeerror:(NSError **)error
public RasterCommentMetadata readComment(ILeadStream stream, int pageNumber, RasterCommentMetadataType type) public:RasterCommentMetadata^ ReadComment(Stream^ stream,int pageNumber,RasterCommentMetadataType type)
def ReadComment(self,stream,pageNumber,type):
stream
A Stream containing the input file data.
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.
using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Color;using Leadtools.Svg;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 TIFDebug.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");Debug.WriteLine("Writing the following comment:");Debug.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);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 passIList<RasterCommentMetadata> comments = new List<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(destFileName, 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(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:Debug.WriteLine(comment.ToAscii());break;case RasterCommentMetadataDataType.Byte:byteData = comment.ToByte();for (int i = 0; i < byteData.Length; i++)Console.Write("{0:X} ", byteData[i]);Debug.WriteLine(" ");break;case RasterCommentMetadataDataType.Int16:shortData = comment.ToInt16();for (int i = 0; i < shortData.Length; i++)Console.Write("{0:X} ", shortData[i]);Debug.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);Debug.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);Debug.WriteLine(" ");break;}}}// Clean upcodecs.Dispose();}static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";}
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
