Leadtools.Codecs Namespace > RasterCodecs Class > ReadTags Method : ReadTags(String,Int32) Method |
public RasterCollection<RasterTagMetadata> ReadTags( string fileName, int pageNumber )
'Declaration Public Overloads Function ReadTags( _ ByVal fileName As String, _ ByVal pageNumber As Integer _ ) As RasterCollection(Of RasterTagMetadata)
'Usage Dim instance As RasterCodecs Dim fileName As String Dim pageNumber As Integer Dim value As RasterCollection(Of RasterTagMetadata) value = instance.ReadTags(fileName, pageNumber)
public RasterCollection<RasterTagMetadata> ReadTags( string fileName, int pageNumber )
function Leadtools.Codecs.RasterCodecs.ReadTags(String,Int32)( fileName , pageNumber )
public: RasterCollection<RasterTagMetadata^>^ ReadTags( String^ fileName, int pageNumber )
To read a specific tag stored in a file, use ReadTag(String,Int32,Int32) and to enumerate all the tag ids (but not the data) stored in a file use EnumTags(String,Int32).
This method will throw an exception if the file format does not support tags. To determine whether a file format supports tags, use TagsSupported. You can also automatically load all the tags stored in a file during a load operation by setting the CodecsLoadOptions.Tags property to true. The tags data will be stored in the resulting image RasterImage.Tags collection.
To load all the tags stored in a stream containing the image data, use ReadTags(Stream,Int32).
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.ImageProcessing Imports Leadtools.ImageProcessing.Color Imports Leadtools.Drawing Public Sub MetadataLoadExample() ' Prompt the user for an image file Dim imageFileName As String = PromptForFileName() ' Initialize LEADTOOLS Using codecs As New RasterCodecs() ' Get the file format Dim format As RasterImageFormat Using info As CodecsImageInfo = codecs.GetInformation(imageFileName, False) format = info.Format End Using ' Load the tags Dim tags As RasterCollection(Of RasterTagMetadata) = Nothing If RasterCodecs.TagsSupported(format) Then tags = codecs.ReadTags(imageFileName, 1) End If ' Load the comments Dim comments As RasterCollection(Of RasterCommentMetadata) = Nothing If RasterCodecs.CommentsSupported(format) Then comments = codecs.ReadComments(imageFileName, 1) End If ' Load the geo keys Dim geoKeys As RasterCollection(Of RasterTagMetadata) = Nothing If RasterCodecs.GeoKeysSupported(format) Then geoKeys = codecs.ReadGeoKeys(imageFileName, 1) End If ' Load the markers Dim markers As RasterCollection(Of RasterMarkerMetadata) = Nothing If RasterCodecs.MarkersSupported(format) Then markers = codecs.ReadMarkers(imageFileName) End If Dim txtFileName As String = Path.Combine( _ Path.GetDirectoryName(imageFileName), _ Path.GetFileNameWithoutExtension(imageFileName) + "_metadata.txt") Using writer As StreamWriter = 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) End Using ' Show the text file we created System.Diagnostics.Process.Start(txtFileName) End Using End Sub Private Shared Sub WriteTags(ByVal writer As StreamWriter, ByVal name As String, ByVal tags As RasterCollection(Of RasterTagMetadata)) writer.WriteLine("{0}:", name) If Not IsNothing(tags) Then For Each tag As RasterTagMetadata In tags writer.WriteLine("Id: 0x{0}, data length: {1}", tag.Id.ToString("X"), tag.GetData().Length) Next Else writer.WriteLine("Not supported") End If writer.WriteLine() End Sub Private Shared Sub WriteComments(ByVal writer As StreamWriter, ByVal comments As RasterCollection(Of RasterCommentMetadata)) writer.WriteLine("Comments:") If Not IsNothing(comments) Then For Each comment As RasterCommentMetadata In comments writer.WriteLine("Type: {0}, data length: {1}", comment.Type, comment.GetData().Length) Next Else writer.WriteLine("Not supported") End If writer.WriteLine() End Sub Private Shared Sub WriteMarkers(ByVal writer As StreamWriter, ByVal markers As RasterCollection(Of RasterMarkerMetadata)) writer.WriteLine("Comments:") If Not IsNothing(markers) Then For Each marker As RasterMarkerMetadata In markers writer.WriteLine("ID: {0}, data length: {1}", marker.Id, marker.GetData().Length) Next Else writer.WriteLine("Not supported") End If writer.WriteLine() End Sub
using Leadtools; using Leadtools.Codecs; using Leadtools.ImageProcessing; using Leadtools.ImageProcessing.Color; public void MetadataLoadExample() { // Prompt the user for an image file string imageFileName = PromptForFileName(); // 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 RasterCollection<RasterTagMetadata> tags = null; if (RasterCodecs.TagsSupported(format)) tags = codecs.ReadTags(imageFileName, 1); // Load the comments RasterCollection<RasterCommentMetadata> comments = null; if (RasterCodecs.CommentsSupported(format)) comments = codecs.ReadComments(imageFileName, 1); // Load the geo keys RasterCollection<RasterTagMetadata> geoKeys = null; if (RasterCodecs.GeoKeysSupported(format)) geoKeys = codecs.ReadGeoKeys(imageFileName, 1); // Load the markers RasterCollection<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 System.Diagnostics.Process.Start(txtFileName); } } private static void WriteTags(StreamWriter writer, string name, RasterCollection<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, RasterCollection<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, RasterCollection<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(); }
RasterCodecsExamples.prototype.MetadataLoadExample = function () { Tools.SetLicense(); with (Leadtools) { with (Leadtools.Codecs) { //Point this to a file with tags, comments, markers, or geokeys var imageFileName = "Assets\\3polars.tif"; // Initialize LEADTOOLS var codecs = new RasterCodecs(); // Get the file format var format; var loadFile; var tags = null; var comments = null; var geoKeys = null; var markers = null; return Tools.AppInstallFolder().getFileAsync(imageFileName).then(function (loadFileX) { loadFile = loadFileX; return codecs.getInformationAsync(LeadStreamFactory.create(loadFile), false, 1) }) .then(function (info) { format = info.format; info.close(); // Load the tags var tags = null; var async1 = null var async2 = null; var async3 = null; var async4 = null; if (RasterCodecs.tagsSupported(format)) async1 = codecs.readTagsAsync(LeadStreamFactory.create(loadFile), 1).then(function (tgs) { tags = tgs; }); // Load the comments if (RasterCodecs.commentsSupported(format)) async2 = codecs.readCommentsAsync(LeadStreamFactory.create(loadFile), 1).then(function (cmnts) { comments = cmnts; }); // Load the geo keys if (RasterCodecs.geoKeysSupported(format)) async3 = codecs.readGeoKeysAsync(LeadStreamFactory.create(loadFile), 1).then(function (geo) { geoKeys = geo; }); // Load the markers if (RasterCodecs.markersSupported(format)) async4 = codecs.readMarkersAsync(LeadStreamFactory.create(loadFile)).then(function (marks) { markers = marks; }); return WinJS.Promise.join([async1, async2, async3, async4]) }) .then(function () { var txtFileName = "file_metadata.txt"; return Tools.AppLocalFolder().createFileAsync(txtFileName) }) .then(function (saveFile) { return saveFile.openAsync(Windows.Storage.FileAccessMode.readWrite) }) .then(function (stream) { writer = Windows.Storage.Streams.DataWriter(stream); // 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); return writer.storeAsync ( ) }) .then(function () { writer.close(); codecs.close(); }); } } } function WriteTags(writer, name, tags) { writer.writeString(name); if (tags != null) { for ( var i = 0; i < tags.length; i++ ) { var tag = tags[i] ; writer.writeString("Id: " + tag.id.toString() + ", data length: ", tag.getData().length); } } else { writer.writeString("Not supported"); } } function WriteComments(writer, comments) { writer.writeString("Comments:"); if (comments != null) { for ( var i = 0; i < comments.length; i++ ) { var comment = comments [ i ] ; writer.writeString("Type: " + comment.type + ", data length: ", comment.getData().length); } } else { writer.writeString("Not supported"); } } function WriteMarkers(writer, markers) { writer.writeString("Markers:"); if (markers != null) { for (var i = 0; i < markers.length; i++) { var marker = markers[i]; writer.writeString("ID: " + marker.id + ", data length: ", marker.getData().length); } } else { writer.writeString("Not supported"); } }
using Leadtools; using Leadtools.Codecs; using Leadtools.ImageProcessing; using Leadtools.ImageProcessing.Color; public async Task MetadataLoadExample() { //Point this to a file with tags, comments, markers, or geokeys string imageFileName = _tifFileWithTags; // Initialize LEADTOOLS using (RasterCodecs codecs = new RasterCodecs()) { // Get the file format RasterImageFormat format; StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(imageFileName); using (CodecsImageInfo info = await codecs.GetInformationAsync(LeadStreamFactory.Create(loadFile), false, 1)) { format = info.Format; } // Load the tags IList<RasterTagMetadata> tags = null; if (RasterCodecs.TagsSupported(format)) tags = await codecs.ReadTagsAsync(LeadStreamFactory.Create(loadFile), 1); // Load the comments IList<RasterCommentMetadata> comments = null; if (RasterCodecs.CommentsSupported(format)) comments = await codecs.ReadCommentsAsync(LeadStreamFactory.Create(loadFile), 1); // Load the geo keys IList<RasterTagMetadata> geoKeys = null; if (RasterCodecs.GeoKeysSupported(format)) geoKeys = await codecs.ReadGeoKeysAsync(LeadStreamFactory.Create(loadFile), 1); // Load the markers IList<RasterMarkerMetadata> markers = null; if (RasterCodecs.MarkersSupported(format)) markers = await codecs.ReadMarkersAsync(LeadStreamFactory.Create(loadFile)); string txtFileName = Path.Combine(Path.GetFileNameWithoutExtension(imageFileName) + "_metadata.txt"); StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(txtFileName); using (StreamWriter writer = new StreamWriter(await saveFile.OpenStreamForWriteAsync())) { // 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); } } } 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(); }
using Leadtools; using Leadtools.Codecs; using Leadtools.Examples; using Leadtools.ImageProcessing; using Leadtools.ImageProcessing.Color; using Leadtools.Windows.Media; public void MetadataLoadExample(Stream inStreamImage, StreamWriter outStreamText) { // Initialize LEADTOOLS RasterCodecs codecs = new RasterCodecs(); { // Get the file format RasterImageFormat format; CodecsImageInfo info = codecs.GetInformation(inStreamImage, false); { format = info.Format; } // Load the tags RasterCollection<RasterTagMetadata> tags = null; if(RasterCodecs.TagsSupported(format)) tags = codecs.ReadTags(inStreamImage, 1); // Load the comments RasterCollection<RasterCommentMetadata> comments = null; if(RasterCodecs.CommentsSupported(format)) comments = codecs.ReadComments(inStreamImage, 1); // Load the geo keys RasterCollection<RasterTagMetadata> geoKeys = null; if(RasterCodecs.GeoKeysSupported(format)) geoKeys = codecs.ReadGeoKeys(inStreamImage, 1); // Write the tags WriteTags(outStreamText, "Tags", tags); // Write the comments WriteComments(outStreamText, comments); // Write the geo keys (tags and geokeys use the same data type) WriteTags(outStreamText, "GeoKeys", geoKeys); } } private static void WriteTags(StreamWriter writer, string name, RasterCollection<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, RasterCollection<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(); }
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.ImageProcessing Imports Leadtools.ImageProcessing.Color Imports Leadtools.Windows.Media Public Sub MetadataLoadExample(ByVal inStreamImage As Stream, ByVal outStreamText As StreamWriter) ' Initialize LEADTOOLS Dim codecs As RasterCodecs = New RasterCodecs() ' Get the file format Dim format As RasterImageFormat Dim info As CodecsImageInfo = codecs.GetInformation(inStreamImage, False) format = info.Format ' Load the tags Dim tags As RasterCollection(Of RasterTagMetadata) = Nothing If RasterCodecs.TagsSupported(format) Then tags = codecs.ReadTags(inStreamImage, 1) End If ' Load the comments Dim comments As RasterCollection(Of RasterCommentMetadata) = Nothing If RasterCodecs.CommentsSupported(format) Then comments = codecs.ReadComments(inStreamImage, 1) End If ' Load the geo keys Dim geoKeys As RasterCollection(Of RasterTagMetadata) = Nothing If RasterCodecs.GeoKeysSupported(format) Then geoKeys = codecs.ReadGeoKeys(inStreamImage, 1) End If ' Write the tags WriteTags(outStreamText, "Tags", tags) ' Write the comments WriteComments(outStreamText, comments) ' Write the geo keys (tags and geokeys use the same data type) WriteTags(outStreamText, "GeoKeys", geoKeys) End Sub Private Shared Sub WriteTags(ByVal writer As StreamWriter, ByVal name As String, ByVal tags As RasterCollection(Of RasterTagMetadata)) writer.WriteLine("{0}:", name) If Not tags Is Nothing Then For Each tag As RasterTagMetadata In tags writer.WriteLine("Id: 0x{0}, data length: {1}", tag.Id.ToString("X"), tag.GetData().Length) Next tag Else writer.WriteLine("Not supported") End If writer.WriteLine() End Sub Private Shared Sub WriteComments(ByVal writer As StreamWriter, ByVal comments As RasterCollection(Of RasterCommentMetadata)) writer.WriteLine("Comments:") If Not comments Is Nothing Then For Each comment As RasterCommentMetadata In comments writer.WriteLine("Type: {0}, data length: {1}", comment.Type, comment.GetData().Length) Next comment Else writer.WriteLine("Not supported") End If writer.WriteLine() End Sub
RasterCodecs Class
RasterCodecs Members
Overload List
TagsSupported Method
ReadTag(String,Int32,Int32) Method
EnumTags(String,Int32) Method
CommentsSupported Method
GeoKeysSupported Method
Tags Property
RasterImage.Tags
Working with Markers
Implementing TIFF Comments and Tags
TIFF File Comments
Implementing GeoKeys (GeoTIFF tags)
Leadtools.RasterCommentMetadataType