Leadtools.Barcode Namespace > BarcodeReader Class > LoadOptions Method : LoadOptions(String) Method |
'Usage Dim instance As BarcodeReader Dim fileName As String instance.LoadOptions(fileName)
ObjectiveC Syntax
function Leadtools.Barcode.BarcodeReader.LoadOptions(String)( fileName )
The load/save methods are provided as helper methods for the user. The BarcodeEngine, BarcodeReader and BarcodeWriter do not use these methods internally.
The default read options can be retrieved using the GetDefaultOptions or GetAllDefaultOptions methods. You can then change the values of the BarcodeReadOptions object returned (or cast it back to the appropriate derived class). These options are used by the ReadBarcode and ReadBarcodes methods when no explicit options are passed by the user.
To save the default options to an XML file, use BarcodeReader.SaveOptions(string fileName).
To save and load data to an XML stream, use BarcodeReader.SaveOptions(Stream stream) and BarcodeReader.LoadOptions(Stream stream).
Public Sub BarcodeReader_LoadSaveOptionsExample() Dim xmlFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "MyReadOptions.xml") Dim engine1 As New BarcodeEngine() Dim reader1 As BarcodeReader = engine1.Reader ' Show a few of the default options ShowReaderOptions("Default options 1:", reader1) ' Change some options Dim oneDReadOptions As OneDBarcodeReadOptions = DirectCast(reader1.GetDefaultOptions(BarcodeSymbology.UPCA), OneDBarcodeReadOptions) oneDReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical Dim qrReadOptions As QRBarcodeReadOptions = DirectCast(reader1.GetDefaultOptions(BarcodeSymbology.QR), QRBarcodeReadOptions) qrReadOptions.EnableDoublePass = True ' Show them ShowReaderOptions("New options 1:", reader1) ' Save the options to an XML file reader1.SaveOptions(xmlFileName) ' Now create another BarcodeReader ' We could use the same one, but this example will show that changing the options ' for one BarcodeReader will not change it in any other in the application Dim engine2 As New BarcodeEngine() Dim reader2 As BarcodeReader = engine2.Reader ' Show a few of the default options, should be the same as the first default options ShowReaderOptions("Default options 2:", reader2) ' Load the options we just saved reader2.LoadOptions(xmlFileName) ' Show them, should be the same as the new options in reader1 ShowReaderOptions("Loaded options 2:", reader2) End Sub Private Sub ShowReaderOptions(ByVal message As String, ByVal reader As BarcodeReader) Console.WriteLine(message) Dim oneDReadOptions As OneDBarcodeReadOptions = DirectCast(reader.GetDefaultOptions(BarcodeSymbology.UPCA), OneDBarcodeReadOptions) Console.WriteLine("OneDBarcodeReadOptions.SearchDirection: {0}", oneDReadOptions.SearchDirection) Dim qrReadOptions As QRBarcodeReadOptions = DirectCast(reader.GetDefaultOptions(BarcodeSymbology.QR), QRBarcodeReadOptions) Console.WriteLine("QRBarcodeReadOptions.EnableDoublePass: {0}", qrReadOptions.EnableDoublePass) Console.WriteLine("---------------") End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
public void BarcodeReader_LoadSaveOptionsExample() { string xmlFileName = Path.Combine(LEAD_VARS.ImagesDir, "MyReadOptions.xml"); BarcodeEngine engine1 = new BarcodeEngine(); BarcodeReader reader1 = engine1.Reader; // Show a few of the default options ShowReaderOptions("Default options 1:", reader1); // Change some options OneDBarcodeReadOptions oneDReadOptions = reader1.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeReadOptions; oneDReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical; QRBarcodeReadOptions qrReadOptions = reader1.GetDefaultOptions(BarcodeSymbology.QR) as QRBarcodeReadOptions; qrReadOptions.EnableDoublePass = true; // Show them ShowReaderOptions("New options 1:", reader1); // Save the options to an XML file reader1.SaveOptions(xmlFileName); // Now create another BarcodeReader // We could use the same one, but this example will show that changing the options // for one BarcodeReader will not change it in any other in the application BarcodeEngine engine2 = new BarcodeEngine(); BarcodeReader reader2 = engine2.Reader; // Show a few of the default options, should be the same as the first default options ShowReaderOptions("Default options 2:", reader2); // Load the options we just saved reader2.LoadOptions(xmlFileName); // Show them, should be the same as the new options in reader1 ShowReaderOptions("Loaded options 2:", reader2); } private void ShowReaderOptions(string message, BarcodeReader reader) { Console.WriteLine(message); OneDBarcodeReadOptions oneDReadOptions = reader.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeReadOptions; Console.WriteLine("OneDBarcodeReadOptions.SearchDirection: {0}", oneDReadOptions.SearchDirection); QRBarcodeReadOptions qrReadOptions = reader.GetDefaultOptions(BarcodeSymbology.QR) as QRBarcodeReadOptions; Console.WriteLine("QRBarcodeReadOptions.EnableDoublePass: {0}", qrReadOptions.EnableDoublePass); Console.WriteLine("---------------"); } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }
//[TestMethod] //public void BarcodeReader_LoadSaveOptionsExample() //{ // string xmlFileName = @"MyReadOptions.xml"; // BarcodeEngine engine1 = new BarcodeEngine(); // BarcodeReader reader1 = engine1.Reader; // // Show a few of the default options // ShowReaderOptions("Default options 1:", reader1); // // Change some options // OneDBarcodeReadOptions oneDReadOptions = reader1.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeReadOptions; // oneDReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical; // QRBarcodeReadOptions qrReadOptions = reader1.GetDefaultOptions(BarcodeSymbology.QR) as QRBarcodeReadOptions; // qrReadOptions.EnableDoublePass = true; // // Show them // ShowReaderOptions("New options 1:", reader1); // // Save the options to an XML file // reader1.SaveOptions(xmlFileName); // // Now create another BarcodeReader // // We could use the same one, but this example will show that changing the options // // for one BarcodeReader will not change it in any other in the application // BarcodeEngine engine2 = new BarcodeEngine(); // BarcodeReader reader2 = engine2.Reader; // // Show a few of the default options, should be the same as the first default options // ShowReaderOptions("Default options 2:", reader2); // // Load the options we just saved // reader2.LoadOptions(xmlFileName); // // Show them, should be the same as the new options in reader1 // ShowReaderOptions("Loaded options 2:", reader2); //} //private void ShowReaderOptions(string message, BarcodeReader reader) //{ // Debug.WriteLine(message); // OneDBarcodeReadOptions oneDReadOptions = reader.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeReadOptions; // Debug.WriteLine("OneDBarcodeReadOptions.SearchDirection: {0}", oneDReadOptions.SearchDirection); // QRBarcodeReadOptions qrReadOptions = reader.GetDefaultOptions(BarcodeSymbology.QR) as QRBarcodeReadOptions; // Debug.WriteLine("QRBarcodeReadOptions.EnableDoublePass: {0}", qrReadOptions.EnableDoublePass); // Debug.WriteLine("---------------"); //}
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2