←Select platform

Tags Property

Summary
The collection of tag data used when reading and writing certain file formats (including TIFF).
Syntax
C#
VB
Objective-C
C++
Java
public ObservableCollection<RasterTagMetadata> Tags { get; } 
Public ReadOnly Property Tags As ObservableCollection(Of RasterTagMetadata) 
@property (nonatomic, assign, readonly, nullable) NSMutableArray<LTRasterTagMetadata *> *tags 
public List<RasterTagMetadata> getTags() 
public: 
property ObservableCollection<RasterTagMetadata^>^ Tags { 
   ObservableCollection<RasterTagMetadata^>^ get(); 
} 

Property Value

A collection of RasterTagMetadata used when reading and writing certain file formats (including TIFF).

Remarks

Several formats allow you to store non-image data such as comments, tags, and markers.

You can manipulate the tags of an image by adding/removing RasterTagMetadata objects to this collection.

By setting the CodecsSaveOptions.Tags property to true before calling RasterCodecs.Save, you can save the tags in this collection when the image is saved into a file.

By setting the CodecsLoadOptions.Markers property to true before calling RasterCodecs.Load, you can load all the markers (if any) into this collection when an image is loaded from a file.

You can use the RasterCodecs.WriteTags method to save the tags directly to an existing file and the RasterCodecs.EnumTags to load the tags stored in an existing file.

Note: To write tags to a TIFF file, use RasterCodecs.WriteTags instead of using RasterImage.Tags followed by RasterCodecs.Save.

Example
C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Core; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Dicom; 
using Leadtools.Drawing; 
using Leadtools.Controls; 
using Leadtools.Svg; 
 
 
private void DisplayTag(RasterTagMetadata tag) 
{ 
	switch (tag.DataType) 
	{ 
		case RasterTagMetadataDataType.Ascii: 
			MessageBox.Show("Tag " + tag.Id.ToString() + " = " + tag.ToAscii()); 
			break; 
		case RasterTagMetadataDataType.Byte: 
			MessageBox.Show("Tag " + tag.Id.ToString() + " = " + tag.ToByte()[0].ToString()); 
			break; 
	} 
} 
		public void TagsExample() 
{ 
	RasterCodecs codecs = new RasterCodecs(); 
	RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1.CMP")); 
 
	//Ascii 
	RasterTagMetadata tagDataAscii = new RasterTagMetadata(); 
	// set the Copyright tag 
	tagDataAscii.Id = 0x8000; 
	tagDataAscii.DataType = RasterTagMetadataDataType.Ascii; 
	tagDataAscii.FromAscii("Test String"); 
	image.Tags.Add(tagDataAscii); 
 
	//Byte 
	RasterTagMetadata tagDataByte = tagDataAscii.Clone(); 
	tagDataByte.Id = 0x8001; 
	tagDataByte.DataType = RasterTagMetadataDataType.Byte; 
	byte[] byteArray = new byte[1]; 
	byteArray[0] = 10; 
	tagDataByte.FromByte(byteArray); 
	image.Tags.Add(tagDataByte); 
 
	codecs.Options.Save.Tags = true; 
	codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1_TAGS.TIF"), RasterImageFormat.Tif, 0); 
	// load the tags together with the image 
 
	RasterTagMetadata tag = codecs.ReadTag(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1_TAGS.TIF"), 1, 0x8000); 
	DisplayTag(tag); 
	tag = codecs.ReadTag(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1_TAGS.TIF"), 1, 0x8001); 
	DisplayTag(tag); 
 
	codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS21\Resources\Images"; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
Imports Leadtools.ImageProcessing.Core 
Imports Leadtools.ImageProcessing.Color 
Imports Leadtools.Controls 
Imports Leadtools.Dicom 
Imports Leadtools.Drawing 
Imports Leadtools.Svg 
 
Private Sub DisplayTag(ByVal tag As RasterTagMetadata) 
   Select Case tag.DataType 
      Case RasterTagMetadataDataType.Ascii 
         MessageBox.Show("Tag " & tag.Id.ToString() & " = " & tag.ToAscii()) 
      Case RasterTagMetadataDataType.Byte 
         MessageBox.Show("Tag " & tag.Id.ToString() & " = " & tag.ToByte()(0).ToString()) 
   End Select 
End Sub 
Public Sub TagsExample() 
   Dim codecs As RasterCodecs = New RasterCodecs() 
   Dim image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1.CMP")) 
 
   'Ascii 
   Dim tagDataAscii As RasterTagMetadata = New RasterTagMetadata() 
   ' set the Copyright tag 
   tagDataAscii.Id = &H8000 
   tagDataAscii.DataType = RasterTagMetadataDataType.Ascii 
   tagDataAscii.FromAscii("Test String") 
   image.Tags.Add(tagDataAscii) 
 
   'Byte 
   Dim tagDataByte As RasterTagMetadata = tagDataAscii.Clone() 
   tagDataByte.Id = &H8001 
   tagDataByte.DataType = RasterTagMetadataDataType.Byte 
   Dim byteArray As Byte() = New Byte(0) {} 
   byteArray(0) = 10 
   tagDataByte.FromByte(byteArray) 
   image.Tags.Add(tagDataByte) 
 
   codecs.Options.Save.Tags = True 
   codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1_TAGS.TIF"), RasterImageFormat.Tif, 0) 
   ' load the tags together with the image 
 
   Dim tag As RasterTagMetadata = codecs.ReadTag(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1_TAGS.TIF"), 1, &H8000) 
   DisplayTag(tag) 
   tag = codecs.ReadTag(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1_TAGS.TIF"), 1, &H8001) 
   DisplayTag(tag) 
 
   codecs.Dispose() 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\LEADTOOLS21\Resources\Images" 
End Class 
Requirements

Target Platforms

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

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