←Select platform

ReadComments(Stream,int) Method

Summary
Gets all the comment fields stored in a stream.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public IList<RasterCommentMetadata> ReadComments( 
   Stream stream, 
   int pageNumber 
) 
- (nullable NSArray<LTRasterCommentMetadata *> *)readCommentsFromStream:(LTLeadStream *)stream  
                                                             pageNumber:(NSInteger)pageNumber  
                                                                  error:(NSError **)error 
public List<RasterCommentMetadata> readComments(ILeadStream stream, int pageNumber) 
public: 
IList<RasterCommentMetadata^>^ ReadComments(  
   Stream^ stream, 
   int pageNumber 
)  
def ReadComments(self,stream,pageNumber): 

Parameters

stream
A Stream containing the input image data.

pageNumber
1-based index of the page from which to read the comments.

Return Value

A collection of RasterTagMetadata containing all the comment fields information found in the file. If the file does not contain any comments, an empty collection will be returned. If the file format does not support comment fields, an exception will be thrown.

Remarks

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.

To read a specific comment field stored in a file, use ReadComment.

This method will throw an exception if the file format does not support comments fields. To determine whether a file format supports comment fields, use CommentsSupported. You can also automatically load all the comment fields stored in a file during a load operation by setting the CodecsLoadOptions.Comments property to true. The comment fields data will be stored in the resulting image RasterImage.Comments collection.

To load all the comments stored in a disk file, use ReadComments.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
public void MetadataLoadExample() 
{ 
   // Prompt the user for an image file 
   string imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "test_GeoKey.TIF"); 
 
   // Initialize LEADTOOLS 
   using (RasterCodecs codecs = new RasterCodecs()) 
   { 
      // Get the file format 
      RasterImageFormat format; 
 
      using (CodecsImageInfo info = codecs.GetInformation(imageFileName, false)) 
      { 
         format = info.Format; 
      } 
 
      // Load the tags 
      IList<RasterTagMetadata> tags = null; 
      if (RasterCodecs.TagsSupported(format)) 
         tags = codecs.ReadTags(imageFileName, 1); 
 
      // Load the comments 
      IList<RasterCommentMetadata> comments = null; 
      if (RasterCodecs.CommentsSupported(format)) 
         comments = codecs.ReadComments(imageFileName, 1); 
 
      // Load the geo keys 
      IList<RasterTagMetadata> geoKeys = null; 
      if (RasterCodecs.GeoKeysSupported(format)) 
         geoKeys = codecs.ReadGeoKeys(imageFileName, 1); 
 
      // Load the markers 
      IList<RasterMarkerMetadata> markers = null; 
      if (RasterCodecs.MarkersSupported(format)) 
         markers = codecs.ReadMarkers(imageFileName); 
 
      string txtFileName = Path.Combine( 
         Path.GetDirectoryName(imageFileName), 
         Path.GetFileNameWithoutExtension(imageFileName) + "_metadata.txt"); 
 
      using (StreamWriter writer = File.CreateText(txtFileName)) 
      { 
         // Write the tags 
         WriteTags(writer, "Tags", tags); 
 
         // Write the comments 
         WriteComments(writer, comments); 
 
         // Write the geo keys (tags and geokeys use the same data type) 
         WriteTags(writer, "GeoKeys", geoKeys); 
 
         // Write the markers 
         WriteMarkers(writer, markers); 
      } 
 
      // Show the text file we created 
      Trace.Write(File.ReadAllText(txtFileName)); 
   } 
} 
 
private static void WriteTags(StreamWriter writer, string name, IList<RasterTagMetadata> tags) 
{ 
   writer.WriteLine("{0}:", name); 
 
   if (tags != null) 
   { 
      foreach (RasterTagMetadata tag in tags) 
      { 
         writer.WriteLine("Id: 0x{0}, data length: {1}", tag.Id.ToString("X"), tag.GetData().Length); 
      } 
   } 
   else 
   { 
      writer.WriteLine("Not supported"); 
   } 
 
   writer.WriteLine(); 
} 
 
private static void WriteComments(StreamWriter writer, IList<RasterCommentMetadata> comments) 
{ 
   writer.WriteLine("Comments:"); 
 
   if (comments != null) 
   { 
      foreach (RasterCommentMetadata comment in comments) 
      { 
         writer.WriteLine("Type: {0}, data length: {1}", comment.Type, comment.GetData().Length); 
      } 
   } 
   else 
   { 
      writer.WriteLine("Not supported"); 
   } 
 
   writer.WriteLine(); 
} 
 
private static void WriteMarkers(StreamWriter writer, IList<RasterMarkerMetadata> markers) 
{ 
   writer.WriteLine("Markers:"); 
 
   if (markers != null) 
   { 
      foreach (RasterMarkerMetadata marker in markers) 
      { 
         writer.WriteLine("ID: {0}, data length: {1}", marker.Id, marker.GetData().Length); 
      } 
   } 
   else 
   { 
      writer.WriteLine("Not supported"); 
   } 
 
   writer.WriteLine(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 22.0.2023.5.5
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Codecs Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.