LEADTOOLS画像ファイルサポート(Leadtools.Codecsアセンブリ)

フレームを表示

ReadExtensions(String、Int32)メソッド








入力ファイル名。
拡張を格納するファイルの中のページの1から始まるインデックス。
指定されたExifファイルから拡張をロードします。
構文
public CodecsExtensionList ReadExtensions( 
   string fileName,
   int pageNumber
)
'Declaration
 
Public Overloads Function ReadExtensions( _
   ByVal fileName As String, _
   ByVal pageNumber As Integer _
) As CodecsExtensionList
'Usage
 
Dim instance As RasterCodecs
Dim fileName As String
Dim pageNumber As Integer
Dim value As CodecsExtensionList
 
value = instance.ReadExtensions(fileName, pageNumber)
public CodecsExtensionList ReadExtensions( 
   string fileName,
   int pageNumber
)
- (nullable LTCodecsExtensionList *)readExtensionsFromFile:(NSString *)file 
                                                pageNumber:(NSInteger)pageNumber 
                                                     error:(NSError **)error
            
 function Leadtools.Codecs.RasterCodecs.ReadExtensions(String,Int32)( 
   fileName ,
   pageNumber 
)
public:
CodecsExtensionList^ ReadExtensions( 
   String^ fileName,
   int pageNumber
) 

パラメーター

fileName
入力ファイル名。
pageNumber
拡張を格納するファイルの中のページの1から始まるインデックス。

戻り値

このファイルで見つけられる拡張を格納するCodecsExtensionListオブジェクト。
解説

すべてのExifファイルに拡張機能があるわけではありません。

現時点では、このメソッドは、Exifファイルだけで機能します。Exifファイルは、「FlashPix拡張」として保存される追加のデータを格納することができます。このメソッドは、この追加のデータにアクセスするのに用いられることができます。LEADTOOLSは、この追加のデータを「拡張」と称します。

使用が終了したときに、このメソッドから返されるCodecsExtensionListは破棄しなければなりません。

サンプル

このサンプルは、Exifファイルに存在するストリームの上で、詳細を示します。

Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.Drawing
Imports Leadtools.Svg

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
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;
using Leadtools.Svg;

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";
}
RasterCodecsExamples.prototype.ExtensionsExample = function () {
   Tools.SetLicense();
   with (Leadtools) {
      with (Leadtools.Codecs) {
         var exifFileName = "Assets\\Extension-audioandstamp.jpg";
         var codecs = new RasterCodecs();

         var stampFileName = "Extension.bmp";

         var stampImage;
         // Read the extensions from the file
         console.info("Reading the extensions from the exif file");
         return Tools.AppInstallFolder().getFileAsync(exifFileName).then(function (loadFile) {
            return codecs.readExtensionsAsync(LeadStreamFactory.create(loadFile), 1)
         })
            .then(function (extensionList) {

               if (extensionList != null) {
                  if ((extensionList.flags & CodecsExtensionListFlags.stamp) == CodecsExtensionListFlags.stamp) {
                     console.info("Stamp extension: Found, saving to ", stampFileName);
                     stampImage = extensionList.createStamp();
                     var async = Tools.AppLocalFolder().createFileAsync(stampFileName);
                     return WinJS.Promise.join(async).then(function (saveFile) {
                        return codecs.saveAsync(stampImage, LeadStreamFactory.create(saveFile), RasterImageFormat.bmp, 24)
                     })
                     .then(function () {
                        stampImage.close();
                     });
                  }
                  else
                     console.info("Stamp extension: Not found");

                  if ((extensionList.flags & CodecsExtensionListFlags.audio) == CodecsExtensionListFlags.audio) {
                     console.info("Audio extension: Found, saving ...");
                     var audioData;
                     var streamIndex = 0;

                     do {
                        var stream;
                        audioData = extensionList.getAudioData(streamIndex);
                        if (audioData != null && audioData.length > 0) {
                           var audioFileName = "Extension" + streamIndex + ".wav";
                           console.info("To ", audioFileName);

                           var async = Tools.AppLocalFolder().createFileAsync(audioFileName);

                           return WinJS.Promise.join(async).then(function (saveFile) {
                              return saveFile.openSequentialReadAsync()
                           })
                           .then(function (stream) {
                              var data = new Array(audioData.length);
                              audioData.getData(0, data, 0, data.length);
                              return stream.writeAsync(data)
                           })
                           .done(function () {
                              stream.close();
                           });
                           streamIndex++;
                        }
                     }
                     while (audioData != null && audioData.length > 0);

                     console.info(streamIndex, " total audio streams found");
                  }
                  else
                     console.info("Audio extension: Not found");

                  var extensions = extensionList.getExtensions();
                  console.info("Total number of extensions found in the file: ", extensions.length);

                  for (var i = 0; i < extensions.length; i++) {
                     var extension = extensions[i];
                     console.info(i, " . Name: " + extension.name + " , Clsid: " + extension.clsid + ", UCDefault: " + extension.ucDefault + ", DatLength: ", extension.data.length);
                  }

                  extensionList.close();
               }
               else
                  console.info("No extensions were found in the file");

               codecs.close();
            });
      }
   }
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;

async Task ExtensionsExample(string exifFileName)
{
   RasterCodecs codecs = new RasterCodecs();
   string stampFileName = "Extension.bmp";
   string audioFileNameTemplate = "Extension{0}.wav";

   // Read the extensions from the file
   Debug.WriteLine("Reading the extensions from the exif file");
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(exifFileName);
   CodecsExtensionList extensionList = await codecs.ReadExtensionsAsync(LeadStreamFactory.Create(loadFile), 1);
   if (extensionList != null)
   {
      if ((extensionList.Flags & CodecsExtensionListFlags.Stamp) == CodecsExtensionListFlags.Stamp)
      {
         Debug.WriteLine("Stamp extension: Found, saving to {0}", stampFileName);
         RasterImage stampImage = extensionList.CreateStamp();
         StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(stampFileName);
         await codecs.SaveAsync(stampImage, LeadStreamFactory.Create(saveFile), RasterImageFormat.Bmp, 24);
         stampImage.Dispose();
      }
      else
         Debug.WriteLine("Stamp extension: Not found");

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

         do
         {
            audioData = extensionList.GetAudioData(streamIndex);
            if (audioData != null && audioData.Length > 0)
            {
               string audioFileName = string.Format(audioFileNameTemplate, streamIndex);
               Debug.WriteLine("To {0}", audioFileName);

               StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(audioFileName);
               using (var stream = await saveFile.OpenStreamForWriteAsync())
               {
                  byte[] data = new byte[audioData.Length];
                  audioData.GetData(0, data, 0, data.Length);
                  stream.Write(data, 0, data.Length);
               }

               streamIndex++;
            }
         }
         while (audioData != null && audioData.Length > 0);

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

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

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

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

   codecs.Dispose();
}
必要条件

ターゲットプラットホーム

参照

参照

RasterCodecsクラス
RasterCodecsメンバ
オーバーロードリスト
Exifファイル拡張子