LEADTOOLS Image File Support (Leadtools.Codecs assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
ReadExtensions(String,Int32) Method
See Also 
Leadtools.Codecs Namespace > RasterCodecs Class > ReadExtensions Method : ReadExtensions(String,Int32) Method



fileName
The input file name.
pageNumber
1-based index of the page within the file that contains the extension.
fileName
The input file name.
pageNumber
1-based index of the page within the file that contains the extension.
Loads extensions from the specified Exif file.

Syntax

Visual Basic (Declaration) 
Overloads Public Function ReadExtensions( _
   ByVal fileName As String, _
   ByVal pageNumber As Integer _
) As CodecsExtensionList
Visual Basic (Usage)Copy Code
Dim instance As RasterCodecs
Dim fileName As String
Dim pageNumber As Integer
Dim value As CodecsExtensionList
 
value = instance.ReadExtensions(fileName, pageNumber)
C# 
public CodecsExtensionList ReadExtensions( 
   string fileName,
   int pageNumber
)
C++/CLI 
public:
CodecsExtensionList^ ReadExtensions( 
   String^ fileName,
   int pageNumber
) 

Parameters

fileName
The input file name.
pageNumber
1-based index of the page within the file that contains the extension.

Return Value

An CodecsExtensionList object that contains the extensions found in this file.

Example

This example will show detailed information on the streams present in the Exif file.

Visual BasicCopy Code
Private Sub ExtensionsExample(ByVal exifFileName As String)
      Dim codecs As RasterCodecs = New RasterCodecs()
      Dim stampFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Extension.bmp")
      Dim audioFileNameTemplate As String = Path.Combine(LEAD_VARS.ImagesDir, "Extension{0}.wav")

      ' Read the extensions from the file
      Console.WriteLine("Reading the extensions from the exif file")
      Dim extensionList As CodecsExtensionList = codecs.ReadExtensions(exifFileName, 1)
      If Not extensionList Is Nothing Then
         If (extensionList.Flags And CodecsExtensionListFlags.Stamp) = CodecsExtensionListFlags.Stamp Then
            Console.WriteLine("Stamp extension: Found, saving to {0}", stampFileName)
            Dim stampImage As RasterImage = extensionList.CreateStamp()
            codecs.Save(stampImage, stampFileName, RasterImageFormat.Bmp, 24)
            stampImage.Dispose()
         Else
            Console.WriteLine("Stamp extension: Not found")
         End If

         If (extensionList.Flags And CodecsExtensionListFlags.Audio) = CodecsExtensionListFlags.Audio Then
            Console.WriteLine("Audio extension: Found, saving ...")
            Dim audioData As RasterNativeBuffer
            Dim streamIndex As Integer = 0

            Do
               audioData = extensionList.GetAudioData(streamIndex)
               If audioData.Data <> IntPtr.Zero Then
                  Dim audioFileName As String = String.Format(audioFileNameTemplate, streamIndex)
                  Console.WriteLine("To {0}", audioFileName)
                  Using fs As FileStream = File.Create(audioFileName)
                     Dim data As Byte() = New Byte(CInt(audioData.Length) - 1) {}
                     Marshal.Copy(audioData.Data, data, 0, CInt(audioData.Length))
                     fs.Write(data, 0, CInt(audioData.Length))
                  End Using

                  streamIndex += 1
               End If
            Loop While audioData.Data <> IntPtr.Zero

            Console.WriteLine("{0} total audio streams found", streamIndex)
         Else
            Console.WriteLine("Audio extension: Not found")
         End If

         Dim extensions As CodecsExtension() = extensionList.GetExtensions()
         Console.WriteLine("Total number of extensions found in the file: {0}", extensions.Length)

         Dim i As Integer = 0
         Do While i < extensions.Length
            Dim extension As CodecsExtension = extensions(i)
            Console.WriteLine(" {0}. Name: {1}, Clsid: {2}, UCDefault: {3}, DatLength: {4}", i, extension.Name, extension.Clsid, extension.UCDefault, extension.DataLength)
            i += 1
         Loop

         extensionList.Dispose()
      Else
         Console.WriteLine("No extensions were found in the file")
      End If

      codecs.Dispose()
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
C#Copy Code
void ExtensionsExample(string exifFileName)
   {
      RasterCodecs codecs = new RasterCodecs();
      string stampFileName = Path.Combine(LEAD_VARS.ImagesDir, "Extension.bmp");
      string audioFileNameTemplate = Path.Combine(LEAD_VARS.ImagesDir, "Extension{0}.wav");

      // Read the extensions from the file
      Console.WriteLine("Reading the extensions from the exif file");
      CodecsExtensionList extensionList = codecs.ReadExtensions(exifFileName, 1);
      if(extensionList != null)
      {
         if((extensionList.Flags & CodecsExtensionListFlags.Stamp) == CodecsExtensionListFlags.Stamp)
         {
            Console.WriteLine("Stamp extension: Found, saving to {0}", stampFileName);
            RasterImage stampImage = extensionList.CreateStamp();
            codecs.Save(stampImage, stampFileName, RasterImageFormat.Bmp, 24);
            stampImage.Dispose();
         }
         else
            Console.WriteLine("Stamp extension: Not found");

         if((extensionList.Flags & CodecsExtensionListFlags.Audio) == CodecsExtensionListFlags.Audio)
         {
            Console.WriteLine("Audio extension: Found, saving ...");
            RasterNativeBuffer audioData;
            int streamIndex = 0;

            do
            {
               audioData = extensionList.GetAudioData(streamIndex);
               if(audioData.Data != IntPtr.Zero)
               {
                  string audioFileName = string.Format(audioFileNameTemplate, streamIndex);
                  Console.WriteLine("To {0}", audioFileName);
                  using(FileStream fs = File.Create(audioFileName))
                  {
                     byte[] data = new byte[audioData.Length];
                     Marshal.Copy(audioData.Data, data, 0, (int)audioData.Length);
                     fs.Write(data, 0, (int)audioData.Length);
                  }

                  streamIndex++;
               }
            }
            while(audioData.Data != IntPtr.Zero);

            Console.WriteLine("{0} total audio streams found", streamIndex);
         }
         else
            Console.WriteLine("Audio extension: Not found");

         CodecsExtension[] extensions = extensionList.GetExtensions();
         Console.WriteLine("Total number of extensions found in the file: {0}", extensions.Length);

         for(int i = 0; i < extensions.Length; i++)
         {
            CodecsExtension extension = extensions[i];
            Console.WriteLine(" {0}. Name: {1}, Clsid: {2}, UCDefault: {3}, DatLength: {4}",
               i, extension.Name, extension.Clsid, extension.UCDefault, extension.DataLength);
         }

         extensionList.Dispose();
      }
      else
         Console.WriteLine("No extensions were found in the file");

      codecs.Dispose();
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
SilverlightCSharpCopy Code
SilverlightVBCopy Code

Remarks

Please note that not all Exif files have extensions.

Currently, this method works only with Exif files. Exif files can contain extra data stored as "FlashPix extensions". This method can be used to access this extra data. Leadtools refers to this extra data as "extensions".

You must dispose the CodecsExtensionList returned from this method when you are done using it.

Requirements

Target Platforms: Silverlight, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only)

See Also