AviCompressor.CompressorData Property
AviCompressorのデータを返す、または設定します。
構文
[VB.NET]
Public CompressorData As Byte()
[C#]public byte[] CompressorData;
備考
返されるデータはコーデックの状態を保存することだけに使用することが推奨されます。配列のデータは変更 されません。不整合なデータがコーデックに渡されるとエラーを返し、コーデックのデータが適合しなくなります。
サンプル
次の例ではどのようにコーデックデータをバイナリファイルへ保存、またはそこからロードする方法を紹介しています。現在使用中のコーデックはグローバル宣言しなければなりません。ローカル宣言した場合、サブ関数の終了後、メモリーから設定が消去され失われてしまいます。完全なサンプルはコーデックのプロパティを保存するプログラマーズガイド>コーデックのプロパティを保存する内の例を参照してください。
コンボボックスで選択されたコーデックからのデータを保存する
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);
}
}
}