AviCompressor.CompressorDataSize Property

構文

[VB.NET]
Public CompressorDataSize As Integer
[C#]
public int CompressorDataSize;

制限

読み取り専用

備考

コーデックプロパティをファイルに保存するのであれば、CompressorDataSize は大変有効です。最初にファイルからサイズ値を読み取り、アプリケーションが適合するサイズの配列を作成してそれがコーデックプロパティを取得します。

サンプル

CompressorDataSizeをどのように使用するかはコーデックのプロパティを保存するプログラマーズガイド>コーデックのプロパティを保存するで紹介しています。
コンボボックスで選択されたコーデックからのデータを保存する。

[C#]
private void cmdSaveCodecData_Click( object sender, System.EventArgs e )
{
     if ( edtConfigFile.Text != "" )
     {
         try
         {
             System.IO.FileStream Filestream = new System.IO.FileStream
         ( edtConfigFile.Text, System.IO.FileMode.Create, System.IO.FileAccess.Write );
             // データのライターを作成する
             System.IO.BinaryWriter BinWriter = new System.IO.BinaryWriter( Filestream );
             // Test.dataにデータを書き込む
             AviCompressor aviComp = null;
             aviComp = ((AviCompressor)(CodecBox.SelectedItem));
             BinWriter.Write( aviComp.ToString() );
             BinWriter.Write( aviComp.CompressorDataSize );
             BinWriter.Write( aviComp.CompressorData );
             BinWriter.Close();
             Filestream.Close();
         }
         catch ( Exception Ex )
         {
             MessageBox.Show( Ex.Message, "Write error", MessageBoxButtons.OK, MessageBoxIcon.Error );
         }
     }
}

以前に保存されたデータをロードしてコーデックに割り当てます。

[C#]
private void cmdLoadCodecData_Click( object sender, System.EventArgs e )
{
     if ( edtConfigFile.Text != "" )
     {
         try
         {
             // データのリーダーを作成する
             System.IO.FileStream Filestrem = new System.IO.FileStream
        ( edtConfigFile.Text, System.IO.FileMode.Open, System.IO.FileAccess.Read );
             System.IO.BinaryReader BinReader =new System.IO.BinaryReader( Filestrem );
             string CodecName = "";
             AviCompressor Codec = null;
             bool CodecFound = false;
             // コーデックコンフィギュレーションファイルからコーデック名を取得
             CodecName = BinReader.ReadString();
             // コンボボックスの中からこのコーデックを検索
             CodecFound = false;
             foreach ( AviCompressor item in CodecBox.Items )
             {
                 if ( item.ToString() == CodecName )
                 {
                     CodecBox.SelectedItem = item;
                     Codec = item;
                     CodecFound = true;
                 }
             }
             if ( CodecFound == true )
             {
                 int codecDataLen = BinReader.ReadInt32();
                 // コンフィギュレーションデータをコーデックに割り当てる
                 Codec.CompressorData = BinReader.ReadBytes( codecDataLen );
             }
             else
             {
                 // コーデックが見つからなかった場合、エラーメッセージを表示
                 MessageBox.Show( "The codec " + CodecName + " was not found!",
             "Load codec configuration", MessageBoxButtons.OK, MessageBoxIcon.Information );
             }
             BinReader.Close();
             Filestrem.Close();
          }
         catch ( Exception Ex )
         {
             MessageBox.Show( Ex.Message, "Read error", MessageBoxButtons.OK, MessageBoxIcon.Error );
         }
     }
}