Leadtools.Codecs Namespace > RasterCodecs Class : ReadTagsWithOffsetsAsync Method |
public IAsyncOperation<IVector<RasterTagMetadata>> ReadTagsWithOffsetsAsync( ILeadStream stream, int pageNumber, IVector<long> offsets )
'Declaration Public Function ReadTagsWithOffsetsAsync( _ ByVal stream As ILeadStream, _ ByVal pageNumber As Integer, _ ByVal offsets As IVector(Of Long) _ ) As IAsyncOperation(Of IVector(Of RasterTagMetadata))
'Usage Dim instance As RasterCodecs Dim stream As ILeadStream Dim pageNumber As Integer Dim offsets As IVector(Of Long) Dim value As IAsyncOperation(Of IVector(Of RasterTagMetadata)) value = instance.ReadTagsWithOffsetsAsync(stream, pageNumber, offsets)
public IAsyncOperation<IVector<RasterTagMetadata>> ReadTagsWithOffsetsAsync( ILeadStream stream, int pageNumber, IVector<long> offsets )
function Leadtools.Codecs.RasterCodecs.ReadTagsWithOffsetsAsync( stream , pageNumber , offsets )
public: IAsyncOperation<IVector<RasterTagMetadata^>^>^ ReadTagsWithOffsetsAsync( ILeadStream^ stream, int pageNumber, IVector<int64>^ offsets )
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 disk file, use ReadTags(String,Int32).
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.ImageProcessing Imports Leadtools.ImageProcessing.Color Imports Leadtools.Drawing Private Shared Sub ReadTagsWithOffsetsExample() ' 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, with their offsets Dim tags As RasterCollection(Of RasterTagMetadata) = Nothing Dim offsets As Long() = Nothing If RasterCodecs.TagsSupported(format) Then tags = codecs.ReadTagsWithOffsets(imageFileName, 1, offsets) 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, offsets) 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), ByVal offsets As Long()) writer.WriteLine("{0}:", name) If Not IsNothing(tags) Then Dim x As Integer = 0 For Each tag As RasterTagMetadata In tags writer.WriteLine("Id: 0x{0}, offset: {1}", tag.Id.ToString("X"), offsets(x)) x = x + 1 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 ReadTagsWithOffsetsExample() { // 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, with their offsets RasterCollection<RasterTagMetadata> tags = null; long[] offsets = null; if (RasterCodecs.TagsSupported(format)) tags = codecs.ReadTagsWithOffsets(imageFileName, 1, out offsets); 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, offsets); } // Show the text file we created System.Diagnostics.Process.Start(txtFileName); } } private static void WriteTags(StreamWriter writer, string name, RasterCollection<RasterTagMetadata> tags, long[] offsets) { writer.WriteLine("{0}:", name); if (tags != null) { int x = 0; foreach (RasterTagMetadata tag in tags) { writer.WriteLine("Id: 0x{0}, offset: {1}", tag.Id.ToString("X"), offsets[x]); x++; } } else { writer.WriteLine("Not supported"); } writer.WriteLine(); }
using Leadtools; using Leadtools.Codecs; using Leadtools.ImageProcessing; using Leadtools.ImageProcessing.Color; public async Task ReadTagsWithOffsetsExample() { 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, with their offsets IList<RasterTagMetadata> tags = null; IList<long> offsets = new List<long>(0); if (RasterCodecs.TagsSupported(format)) tags = await codecs.ReadTagsWithOffsetsAsync(LeadStreamFactory.Create(loadFile), 1, offsets); string txtFileName = 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, offsets); } } } private static void WriteTags(StreamWriter writer, string name, IList<RasterTagMetadata> tags, IList<long> offsets) { writer.WriteLine("{0}:", name); Debug.WriteLine("{0}:", name); if (tags != null) { int x = 0; foreach (RasterTagMetadata tag in tags) { writer.WriteLine("Id: 0x{0}, offset: {1}", tag.Id.ToString("X"), offsets[x]); Debug.WriteLine("Id: 0x{0}, offset: {1}", tag.Id.ToString("X"), offsets[x]); x++; } } else { writer.WriteLine("Not supported"); Debug.WriteLine("Not supported"); } writer.WriteLine(); Debug.WriteLine(""); }
RasterCodecs Class
RasterCodecs Members
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