←Select platform

MarkersSupported Method

Summary
Checks whether the given file format supports markers.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public static bool MarkersSupported( 
   RasterImageFormat format 
) 
+ (BOOL)markersSupported:(LTRasterImageFormat)format 
public static boolean markersSupported(RasterImageFormat format) 
public: 
static bool MarkersSupported(  
   RasterImageFormat format 
)  
def MarkersSupported(self,format): 

Parameters

format
The RasterImageFormat to check

Return Value

true if the format supports markers; otherwise it is false.

Remarks

This is a helper method that can be used to detect if a certain raster file format supports markers. For example, ReadMarkers can be used to read the markers stored in a file. If the file format supports markers, such as EXIF, then these methods will successfully return the markers stored.

However, if the format does not support markers, such as BMP, an exception will be thrown by the RasterCodecs objects. You can use MarkersSupported to determine whether the file supports markers and only call the read methods if the return value is true.

Note that the RasterCodecs option uses this method internally to determine whether the file supports markers when the CodecsLoadOptions.Markers is set to true and only read the file markers if the file format supports them.

Example
C#
Java
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:\LEADTOOLS23\Resources\Images"; 
} 
 
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 metadataLoadExample() throws IOException { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String imageFileName = combine(LEAD_VARS_IMAGES_DIR, "ocr1.tif"); 
   ILeadStream imageFileStream = LeadStreamFactory.create(imageFileName); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   // Get the file format 
   RasterImageFormat format; 
   CodecsImageInfo info = codecs.getInformation(imageFileName, false); 
   format = info.getFormat(); 
 
   // Load the tags 
   List<RasterTagMetadata> tags = null; 
   assertTrue("tags are supported", RasterCodecs.tagsSupported(format)); 
   tags = codecs.readTags(imageFileStream, 1); 
   System.out.println("tags are supported"); 
 
   // Load the comments 
   List<RasterCommentMetadata> comments = null; 
   assertTrue("comments are supported", RasterCodecs.commentsSupported(format)); 
   comments = codecs.readComments(imageFileStream, 1); 
   System.out.println("comments are supported"); 
 
   // Load the geo keys 
   List<RasterTagMetadata> geoKeys = null; 
   assertTrue("geoKeys are supported", RasterCodecs.geoKeysSupported(format)); 
   geoKeys = codecs.readGeoKeys(imageFileStream, 1); 
   System.out.println("geoKeys are supported"); 
 
   // Load the markers 
   List<RasterMarkerMetadata> markers = null; 
   if (RasterCodecs.markersSupported(format)) 
      markers = codecs.readMarkers(imageFileStream); 
 
   File file = new File(imageFileName); 
   String txtFileName = file.getName().substring(0, file.getName().indexOf(".")) + "_metadata.txt"; 
   File txtFile = new File(txtFileName); 
   if (!txtFile.exists()) { 
      txtFile.createNewFile(); 
   } 
   FileWriter txtFileWriter = new FileWriter(txtFileName); 
   LeadStreamFactory.create(txtFileName); 
 
   // Write the tags 
   writeTags(txtFileWriter, "Tags", tags); 
 
   // Write the comments 
   writeComments(txtFileWriter, comments); 
 
   // Write the geo keys (tags and geokeys use the same data type) 
   writeTags(txtFileWriter, "GeoKeys", geoKeys); 
 
   // Write the markers 
   writeMarkers(txtFileWriter, markers); 
 
   // Show the text file we created 
   imageFileStream.close(); 
   txtFileWriter.close(); 
} 
 
private static void writeTags(FileWriter writer, String name, List<RasterTagMetadata> tags) throws IOException { 
   writer.write((name + ":")); 
 
   if (tags != null) { 
      for (RasterTagMetadata tag : tags) { 
         writer.write(String.format("Id: 0x%s, data length: %s%n", tag.getId(), tag.getData().length)); 
      } 
   } else { 
      writer.write("Not supported\n"); 
   } 
 
   writer.write("\n"); 
} 
 
private static void writeComments(FileWriter writer, List<RasterCommentMetadata> comments) throws IOException { 
   writer.write("Comments:"); 
 
   if (comments != null) { 
      for (RasterCommentMetadata comment : comments) { 
         writer.write(String.format("Type: %s, data length: %s%n", comment.getType(), comment.getData().length)); 
      } 
   } else { 
      writer.write("Not supported\n"); 
   } 
 
   writer.write("\n"); 
} 
 
private static void writeMarkers(FileWriter writer, List<RasterMarkerMetadata> markers) throws IOException { 
   writer.write("Markers:"); 
 
   if (markers != null) { 
      for (RasterMarkerMetadata marker : markers) { 
         writer.write("ID: %s, data length: %s", marker.getId(), marker.getData().length); 
      } 
   } else { 
      writer.write("Not supported"); 
   } 
 
   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.