Leadtools Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
RasterMarkerMetadata Class
See Also  Members   Example 
Leadtools Namespace : RasterMarkerMetadata Class



Extends the RasterMetadata class to provide functionality for dealing with marker metadata stored within various image file formats.

Syntax

Visual Basic (Declaration) 
<SerializableAttribute()>
Public Class RasterMarkerMetadata 
   Inherits RasterMetadata
Visual Basic (Usage)Copy Code
Dim instance As RasterMarkerMetadata
C# 
[SerializableAttribute()]
public class RasterMarkerMetadata : RasterMetadata 
C++/CLI 
[SerializableAttribute()]
public ref class RasterMarkerMetadata : public RasterMetadata 

Example

This example will write different markers to an existing tif file then read them as a test.

Visual BasicCopy Code
Public Sub RasterMarkerMetadataExample()
 RasterCodecs.Startup()
 Dim codecs As RasterCodecs = New RasterCodecs()
 codecs.ThrowExceptionsOnInvalidImages = True

 Dim srcFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"
 Dim destFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_markers.tif"

 ' Load the image
 Dim image As RasterImage = codecs.Load(srcFileName)
 codecs.Save(image, destFileName, RasterImageFormat.ExifJpeg, 24)

 image.Dispose()

 ' write a marker to the file
 Dim markerWrite As RasterMarkerMetadata = New RasterMarkerMetadata()
 Dim data As Byte() = New Byte(99) {}
 Dim i As Integer = 0
 Do While i < data.Length
    data(i) = CByte(i + 1)
    i += 1
 Loop
 markerWrite.Id = &HE0
 markerWrite.SetData(data)

 Console.WriteLine("Writing the marker")
 codecs.WriteMarker(destFileName, 1, markerWrite)

 ' read the markers from the file and check for ours
 Dim markers As RasterCollection(Of RasterMarkerMetadata) = codecs.ReadMarkers(destFileName)
 Dim markerRead As RasterMarkerMetadata = Nothing
 i = 0
 Do While i < markers.Count AndAlso markerRead Is Nothing
    If markers(i).Id = markerWrite.Id Then
       markerRead = markers(i)
    End If
    i += 1
 Loop

 Debug.Assert(markerRead.Id = markerWrite.Id)
 Dim dataRead As Byte() = markerRead.GetData()
 Dim dataWrite As Byte() = markerWrite.GetData()
 Debug.Assert(dataRead.Length = dataWrite.Length)
 i = 0
 Do While i < dataRead.Length
    Debug.Assert(dataRead(i) = dataWrite(i))
    i += 1
 Loop

 ' Cleanup
 RasterCodecs.Shutdown()
      End Sub
C#Copy Code
public void RasterMarkerMetadataExample() 

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.ThrowExceptionsOnInvalidImages = true; 
 
   string srcFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"; 
   string destFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_markers.tif"; 
 
   // Load the image 
   RasterImage image = codecs.Load(srcFileName); 
   codecs.Save(image, destFileName, RasterImageFormat.ExifJpeg, 24); 
 
   image.Dispose(); 
 
   // write a marker to the file 
   RasterMarkerMetadata markerWrite = new RasterMarkerMetadata(); 
   byte[] data = new byte[100]; 
   for(int i=0; i < data.Length; i++ ) 
      data[i] = (byte)(i + 1); 
   markerWrite.Id = 0xE0; 
   markerWrite.SetData(data); 
 
   Console.WriteLine("Writing the marker"); 
   codecs.WriteMarker(destFileName, 1, markerWrite); 
 
   // read the markers from the file and check for ours 
   RasterCollection<RasterMarkerMetadata> markers = codecs.ReadMarkers(destFileName); 
   RasterMarkerMetadata markerRead = null; 
   for(int i = 0; i < markers.Count && markerRead == null; i++) 
   { 
      if(markers[i].Id == markerWrite.Id) 
         markerRead = markers[i]; 
   } 
 
   Debug.Assert(markerRead.Id == markerWrite.Id); 
   byte[] dataRead = markerRead.GetData(); 
   byte[] dataWrite = markerWrite.GetData(); 
   Debug.Assert(dataRead.Length == dataWrite.Length); 
   for(int i = 0; i < dataRead.Length; i++) 
      Debug.Assert(dataRead[i] == dataWrite[i]); 
 
   // Cleanup 
   RasterCodecs.Shutdown(); 
}

Remarks

JPEG files contain metadata information in user-defined markers.

The user-defined markers are in the range 0xE0 to 0xFE. These markers can have a maximum size of 0xFFFD, or 65533 bytes.

The markers below 0xE0 are reserved for the encoding of the image and inserting a reserved marker can make a file invalid. Therefore, you should not use reserved markers unless you are well acquainted with markers and image encoding in JPEG files.

TIFF files do not contain markers, however, Leadtools provides a "workaround" for transferring Exif comments from JPEG files to TIFF files, and vice versa. The Exif metadata information from a TIFF file will be loaded as an APP1 marker. Therefore, you can load Exif metadata from an uncompressed file and store it in a compressed Exif file.

You can also take metadata information from a compressed Exif file and store it in an uncompressed Exif file. Please note however, that some information cannot be stored inside uncompressed Exif files. For example, audio data is stored in APP2 markers and there is no built-in support for saving APP2 markers in TIFF files. However, you can still save the audio data yourself, using a custom tag.

Inheritance Hierarchy

System.Object
   Leadtools.RasterMetadata
      Leadtools.RasterMarkerMetadata

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also