AviCompressor.CompressorDataSize Property

Returns the size of the SAFEARRAY of Byte returned by CompressorData.
Syntax:
[VB.NET]
Public CompressorDataSize As Integer
[C#]
public int CompressorDataSize;
Limitations:

Read only.

Remarks:

The CompressorDataSize is useful, if codec properties are to be saved to a file. Reading the size value first from file, enables an application to create an array of the matching size that will get the codec properties.

Sample:

How to use the CompressorDataSize is shown in the sample Saving Codec Properties.

Save the data from a codec that was selected in a combo box.

[VB.NET]
Private Sub cmdSaveCodecData_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles cmdSaveCodecData.Click     If edtConfigFile.Text <> "" Then         Try             Dim Filestream As New System.IO.FileStream(edtConfigFile.Text, System.IO.FileMode.Create, System.IO.FileAccess.Write)               ' Create the writer for data.             Dim BinWriter As New System.IO.BinaryWriter(Filestream)               ' Write data to Test.data.             Dim aviComp As AviCompressor             aviComp = CType(CodecBox.SelectedItem(), AviCompressor)               BinWriter.Write(aviComp.ToString())             BinWriter.Write(aviComp.CompressorDataSize)             BinWriter.Write(aviComp.CompressorData)               BinWriter.Close()             Filestream.Close()           Catch Ex As System.Exception             MsgBox(Ex.Message, MsgBoxStyle.Critical"Write error")         End Try     End If End Sub
[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);               // Create the writer for data.             System.IO.BinaryWriter BinWriter = new System.IO.BinaryWriter(Filestream);               // Write data to 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);         }     } }

Load the previously saved data and assign it to a codec.

[VB.NET]
Private Sub cmdLoadCodecData_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles cmdLoadCodecData.Click     If edtConfigFile.Text <> "" Then         Try             ' Create the reader for data.             Dim Filestrem As New System.IO.FileStream(edtConfigFile.Text, System.IO.FileMode.Open, System.IO.FileAccess.Read)             Dim BinReader As New System.IO.BinaryReader(Filestrem)               Dim CodecName As String             Dim Codec As AviCompressor             Dim CodecFound As Boolean               ' Retrieve the name of the codec from the codec configuration file             CodecName = BinReader.ReadString()               ' Search this codec in the codec combo box             CodecFound = False             For Each item As AviCompressor In CodecBox.Items                 If item.ToString() = CodecName Then                     CodecBox.SelectedItem = item                     Codec = item                     CodecFound = True                 End If             Next               If CodecFound = True Then                 Dim codecDataLen As Integer = BinReader.ReadInt32()                 ' Assign the configuration data to the codec.                 Codec.CompressorData = BinReader.ReadBytes(codecDataLen)             Else                 ' If the codec was not found, display an error message.                 MsgBox("The codec " + CodecName + " was not found!", MsgBoxStyle.Information"Load codec configuration")             End If             BinReader.Close()             Filestrem.Close()           Catch Ex As System.Exception             MsgBox(Ex.Message, MsgBoxStyle.Critical"Read error")         End Try     End If End Sub
[C#]
private void cmdLoadCodecData_Click(object sender, System.EventArgs e) {     if (edtConfigFile.Text != "")     {         try         {             // Create the reader for data.             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;               // Retrieve the name of the codec from the codec configuration file             CodecName = BinReader.ReadString();               // Search this codec in the codec combo box             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();                 // Assign the configuration data to the codec.                 Codec.CompressorData = BinReader.ReadBytes(codecDataLen);             }             else             {                 // If the codec was not found, display an error message.                 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);         }     } }
See Also: AviCompressor, AviCompressor.CompressorData

<< AviCompressor

This site is part of The Imaging Source Network. Other sites include Company Portal, Image Processing, Astronomy Cameras, Astronomy Cameras Blog, Blog caméras d'astronomie, Astronomy Cameras Competition, TX Text Control, TX Text Control Blog and Forums.