Save and Restore Device Properties This short source code snippet illustrates how to save and restore device properties with IC Imaging Control.
IC Imaging Control offers a number of easy-to-use methods to save the current settings of a video capture device to a file and to subsequently restore them. These methods are:
With the button "Device...", the user accesses the built-in dialog to select a video capture device, while the button "Properties..." allows its settings to be adjusted. When the button "Save Settings..." is clicked , the program first checks whether the video capture device is valid (.DeviceValid). Then, CommonDialog1.ShowSave opens the Windows dialog to save a file. When .SaveDeviceStateToFile is called, IC Imaging Control writes the current parameters to the selected file: C# private void btnSaveSettings_Click(object sender, System.EventArgs e) { if( icImagingControl1.DeviceValid ) { SaveFileDialog dlg = new SaveFileDialog(); dlg.AddExtension = true; dlg.DefaultExt = "xml"; dlg.Filter = "Configuration Files (*.xml)|*.xml||"; dlg.OverwritePrompt = true; dlg.RestoreDirectory = true; dlg.Title = "Save Settings"; if( dlg.ShowDialog() == DialogResult.OK ) { icImagingControl1.SaveDeviceStateToFile( dlg.FileName ); } } } When the button "Restore Settings..." is clicked, the program first stops the current image data stream (.LiveStop). Then, CommonDialog1.ShowOpen opens the Windows dialog to open a file. When .LoadDeviceStateFromFile is called, IC Imaging Control reads the parameters from the selected file and tries to open and configure the video capture device, whose properties have previously been written to file. If .LoadDeviceStateFromFile fails, an exception is thrown, thus .LoadDeviceStateFromFile should be encapsulated in a try ... catch block. Finally, .LiveStart restarts the image data stream based on the new parameters. C# private void btnRestoreSettings_Click(object sender, System.EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "Configuration Files (*.xml)|*.xml||"; dlg.RestoreDirectory = true; dlg.Title = "Restore Settings"; if( dlg.ShowDialog() == DialogResult.OK ) { try { // If a device shows a live video, stop it. if (icImagingControl1.LiveVideoRunning) icImagingControl1.LiveStop(); // Load the configuration file. icImagingControl1.LoadDeviceStateFromFile(dlg.FileName, true); // Start the live video again. icImagingControl1.LiveStart(); } catch( TIS.Imaging.ICException ex) { MessageBox.Show(ex.Message,"Failed to Open Device",MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } |