IC Imaging Control .NET

AviCompressor.CompressorData Property

AviCompressor.CompressorData Property

Returns or sets the data of an AviCompressor.
public byte[] CompressorData;

The returned data should only be used to store the state of the codecs. The data in the array is not to be modified. If inconsistent data is passed to the codec, an error is returned. Furthermore, the data of one codec will not match each other.


The following example shows how to save and load codec data into and from a binary file. The codec which is currently used, must be declared globally. If it is declared locally in the sub procedure, it would loose its settings after exiting the sub procedure, because it would be removed from memory. The complete example can be found in the samples directory in Saving Codec Properties.

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

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.

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.CompressorDataSize

<< AviCompressor

Get in touch with us

About The Imaging Source

Established in 1990, The Imaging Source is one of the leading manufacturers of industrial cameras, frame grabbers and video converters for production automation, quality assurance, logistics, medicine, science and security.

Our comprehensive range of cameras with USB 3.1, USB 3.0, USB 2.0, GigE interfaces and other innovative machine vision products are renowned for their high quality and ability to meet the performance requirements of demanding applications.

Automated Imaging Association ISO 9001:2015 certified

Contact us