public static bool TagsSupported(
RasterImageFormat format
)
+ (BOOL)tagsSupported:(LTRasterImageFormat)format
public static boolean tagsSupported(RasterImageFormat format)
public:
static bool TagsSupported(
RasterImageFormat format
)
def TagsSupported(self,format):
format
The RasterImageFormat to check
true if the format supports tags; otherwise it is false.
This is a helper method that can be used to detect if a certain raster file format supports tags. For example, ReadTag, ReadTags and EnumTags can be used to read the tags stored in a file. If the file format supports tags, such as JPEG or TIFF, then these methods will successfully return the tags stored.
However, if the format does not support tags, such as BMP, an exception will be thrown by the RasterCodecs objects. You can use TagsSupported to determine whether the file supports tags and only call the read tags methods if the return value is true.
Note that the RasterCodecs option uses this method internally to determine whether the file supports tags when the CodecsLoadOptions.Tags is set to true and only read the file tags if the file format supports them.
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";
}
ReadTag(String,Int32,Int32) Method
ReadTagsWithOffsets(String,Int32,Int64[]) Method
Implementing TIFF Comments and Tags
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
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.