←Select platform

Comments Property

Summary
Gets or sets a value that indicates whether any comment fields found in the file should be automatically loaded.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public bool Comments { get; set; } 
@property (nonatomic, assign) BOOL comments; 
public boolean getComments() 
public void setComments(boolean value) 
public: 
property bool Comments { 
   bool get(); 
   void set (    bool ); 
} 
Comments # get and set (CodecsLoadOptions) 

Property Value

Value Description
true To enable automatic load of any comment fields found in the file.
false To prevent automatic load of any comment fields found in the file. The default value is false.
Remarks

When the value of the Comments property is set to true, any subsequent load operation performed by this RasterCodecs object will automatically try to load all the comment fields found in the file and store them in the RasterImage.Comments collection of the resulting image.

Internally, the RasterCodecs object will call CommentsSupported on the image and only try to load the comments if the value returned is true.

When loading more than one page from a multipage file, only the comments found in the first page will be automatically loaded when the value of this property is set to true. To manually load all the comments in any page, use ReadComments.

You must set the value of the Markers property to false to enable automatic loading the comments. If the value of both Markers and Comments is set to true, the markers will take take precedence and no comments will be loaded.

Note that any load method that uses tiles, offset or resizing will not load any file metadata automatically regardless of the value of this property.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
public void MetadataAutoLoadExample() 
{ 
   // Prompt the user for an image file 
   string imageFileName = PromptForFileName(); 
 
   // Initialize LEADTOOLS 
   using (RasterCodecs codecs = new RasterCodecs()) 
   { 
      CodecsLoadOptions loadOptions = codecs.Options.Load; 
 
      // Make sure auto-loading of markers is turned off, otherwise, 
      // markers take precedence over loading the other metadata 
      loadOptions.Markers = false; 
 
      // Automatically load any tags, comments and geokeys found in this file 
      loadOptions.Tags = true; 
      loadOptions.Comments = true; 
      loadOptions.GeoKeys = true; 
 
      // Now load the image 
      using (RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)) 
      { 
         string txtFileName = Path.Combine( 
            Path.GetDirectoryName(imageFileName), 
            Path.GetFileNameWithoutExtension(imageFileName) + "_metadata.txt"); 
 
         using (StreamWriter writer = File.CreateText(txtFileName)) 
         { 
            // Show its tags 
            ShowTags(writer, "Tags", image.Tags); 
 
            // Show its comments 
            ShowComments(writer, image.Comments); 
 
            // Show its geo keys (tags and geokeys use the same data type) 
            ShowTags(writer, "GeoKeys", image.GeoKeys); 
         } 
 
         // Show the text file we created 
         System.Diagnostics.Process.Start(txtFileName); 
      } 
   } 
} 
 
private static void ShowTags(StreamWriter writer, string name, IList<RasterTagMetadata> tags) 
{ 
   writer.WriteLine("{0}:", name); 
 
   foreach (RasterTagMetadata tag in tags) 
   { 
      writer.WriteLine("Id: 0x{0}, data length: {1}", tag.Id.ToString("X"), tag.GetData().Length); 
   } 
 
   writer.WriteLine(); 
} 
 
private static void ShowComments(StreamWriter writer, IList<RasterCommentMetadata> comments) 
{ 
   writer.WriteLine("Comments:"); 
 
   foreach (RasterCommentMetadata comment in comments) 
   { 
      writer.WriteLine("Type: 0x{0}, data length: {1}", comment.Type, comment.GetData().Length); 
   } 
 
   writer.WriteLine(); 
} 
 
import java.io.*; 
import java.net.*; 
import java.nio.file.Paths; 
import java.util.*; 
import java.time.Instant; 
import java.time.Duration; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.codecs.RasterCodecs.FeedCallbackThunk; 
import leadtools.drawing.internal.*; 
import leadtools.imageprocessing.*; 
import leadtools.imageprocessing.color.ChangeIntensityCommand; 
import leadtools.svg.*; 
 
 
public void metadataAutoLoadExample() throws IOException { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String imageFileName = combine(LEAD_VARS_IMAGES_DIR, "leadtools.pdf"); 
 
   // Initialize LEADTOOLS 
   RasterCodecs codecs = new RasterCodecs(); 
   CodecsLoadOptions loadOptions = codecs.getOptions().getLoad(); 
 
   // Make sure auto-loading of markers is turned off, otherwise, 
   // markers take precedence over loading the other metadata 
   loadOptions.setMarkers(false); 
 
   // Automatically load any tags, comments and geokeys found in this file 
   loadOptions.setTags(true); 
   loadOptions.setComments(true); 
   loadOptions.setGeoKeys(true); 
 
   // Now load the image 
   RasterImage image = codecs.load(imageFileName, 0, CodecsLoadByteOrder.BGR_OR_GRAY, 1, 1); 
   File file = new File(imageFileName); 
   String txtFileName = combine( 
         LEAD_VARS_IMAGES_DIR, file.getName().substring(0, file.getName().indexOf(".")) + "_metadata.txt"); 
   FileWriter txtFileWriter = new FileWriter(txtFileName); 
 
   // Show its tags 
   showTags(txtFileWriter, "Tags", image.getTags()); 
 
   // Show its comments 
   showComments(txtFileWriter, image.getComments()); 
 
   // Show its geo keys (tags and geokeys use the same data type) 
   showTags(txtFileWriter, "GeoKeys", image.getGeoKeys()); 
} 
 
private static void showTags(FileWriter writer, String name, RasterCollection<RasterTagMetadata> rasterCollection) 
      throws IOException { 
   writer.write(name + ":"); 
 
   for (RasterTagMetadata tag : rasterCollection) { 
      writer.write("Id: 0x" + tag.getId() + ", data length: " + tag.getData().length); 
   } 
 
   writer.write("\n"); 
} 
 
private static void showComments(FileWriter writer, RasterCollection<RasterCommentMetadata> comments) 
      throws IOException { 
   writer.write("Comments:"); 
 
   for (RasterCommentMetadata comment : comments) { 
      writer.write("Type: 0x" + comment.getType() + ", data length: " + comment.getData().length); 
   } 
 
   writer.write("\n"); 
} 
Requirements

Target Platforms

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

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