LEADTOOLS Barcode (Leadtools.Barcode assembly)
LEAD Technologies, Inc

GetDefaultOptions Method (BarcodeReader)

Example 







An BarcodeSymbology enumeration member that specifies the barcode symbology (or type) to get its options.
Gets the default read options for a specified symbology. .NET support Silverlight support
Syntax
public BarcodeReadOptions GetDefaultOptions( 
   BarcodeSymbology symbology
)
'Declaration
 
Public Function GetDefaultOptions( _
   ByVal symbology As BarcodeSymbology _
) As BarcodeReadOptions
'Usage
 
Dim instance As BarcodeReader
Dim symbology As BarcodeSymbology
Dim value As BarcodeReadOptions
 
value = instance.GetDefaultOptions(symbology)
public BarcodeReadOptions GetDefaultOptions( 
   BarcodeSymbology symbology
)
ObjectiveC Syntax
 function Leadtools.Barcode.BarcodeReader.GetDefaultOptions( 
   symbology 
)
public:
BarcodeReadOptions^ GetDefaultOptions( 
   BarcodeSymbology symbology
) 

Parameters

symbology
An BarcodeSymbology enumeration member that specifies the barcode symbology (or type) to get its options.

Return Value

The BarcodeReadOptions derived object used by this BarcodeReader as the default read options to use when reading barcodes of the type specified in symbology.
Remarks

LEADTOOLS provides extra options to use when reading barcodes. These options are used to fine tune the parameters or provide extra pre-known information that are specific to certain types of barcodes. The base abstract class for the options is BarcodeReadOptions. LEADTOOLS provides derived classes for each symbology (or group of symbologies). Refer to BarcodeReadOptions for more information.

The BarcodeReader class contains default options for each barcode symbology (or group of common symbologies). These options can be retrieved using the GetDefaultOptions method passing the symbology of interest. You can then change the members of the returned BarcodeReadOptions (or after casting it to the appropriate derived class). These default options will be used by the BarcodeReader when the user calls the ReadBarcode and ReadBarcodes methods with no specific options (by either using versions of the method that do not take options as a parameter, pass null or Nothing for the options parameter for versions that accept options as a parameter, or finally if the options parameter array does not contain options class that is associated with a read barcode).

You can also create an instance of one of the derived BarcodeReadOptions classes and use it directly in ReadBarcode and ReadBarcodes methods that accept options as a parameter.

BarcodeSymbology.Unknown is a special type that is used to instruct the engine to read all barcodes. It does not have an associated read options class and should not be used in this method, otherwise, an exception will be thrown.

Example
Copy CodeCopy Code  
Public Sub BarcodeReader_GetDefaultOptionsExample()
      Dim imageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Barcode1.tif")

      ' Create a Barcode engine
      Dim engine As New BarcodeEngine()

      ' Get the Barcode reader instance
      Dim reader As BarcodeReader = engine.Reader

      ' Load the image
      Using codecs As New RasterCodecs()
         Using image As RasterImage = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)
            ' Rotate the image by 90, so default option of reading horizonal barcodes will not work
            Console.WriteLine("Rotating the image by 90 degrees")
            Dim rotate As New RotateCommand(90 * 100, RotateCommandFlags.Resize, RasterColor.FromKnownColor(RasterKnownColor.White))
            rotate.Run(image)

            ' Read a UPCA barcode from the image using default options
            Console.WriteLine("Reading barcodes using default options")
            Dim barcode As BarcodeData = reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.UPCA)

            ' Show its location and data if found
            ' This will print out "Not found"
            If Not IsNothing(barcode) Then
               Console.WriteLine("Found a {0} barcode at {1}, data:\n{2}", barcode.Symbology, barcode.Bounds, barcode.Value)
            Else
               Console.WriteLine("Not found")
            End If

            ' Now set the default options for reading 1D barcodes to search for vertical barcodes and try again
            Dim oneDReadOptions As OneDBarcodeReadOptions = DirectCast(reader.GetDefaultOptions(BarcodeSymbology.UPCA), OneDBarcodeReadOptions)
            oneDReadOptions.SearchDirection = BarcodeSearchDirection.Vertical

            ' Read again
            Console.WriteLine("Reading barcodes using new options")
            barcode = reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.UPCA)

            ' Show its location and data if found
            ' This will find the barcode and print its information now
            If Not IsNothing(barcode) Then
               Console.WriteLine("Found a {0} barcode at {1}, data:\n{2}", barcode.Symbology, barcode.Bounds, barcode.Value)
            Else
               Console.WriteLine("Not found")
            End If
         End Using
      End Using
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void BarcodeReader_GetDefaultOptionsExample()
   {
      string imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "Barcode1.tif");

      // Create a Barcode engine
      BarcodeEngine engine = new BarcodeEngine();

      // Get the Barcode reader instance
      BarcodeReader reader = engine.Reader;

      // Load the image
      using(RasterCodecs codecs = new RasterCodecs())
      {
         using(RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1))
         {
            // Rotate the image by 90, so default option of reading horizonal barcodes will not work
            Console.WriteLine("Rotating the image by 90 degrees");
            RotateCommand rotate = new RotateCommand(90 * 100, RotateCommandFlags.Resize, RasterColor.FromKnownColor(RasterKnownColor.White));
            rotate.Run(image);

            // Read a UPCA barcode from the image using default options
            Console.WriteLine("Reading barcodes using default options");
            BarcodeData barcode = reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.UPCA);

            // Show its location and data if found
            // This will print out "Not found"
            if(barcode != null)
            {
               Console.WriteLine("Found a {0} barcode at {1}, data:\n{2}", barcode.Symbology, barcode.Bounds, barcode.Value);
            }
            else
            {
               Console.WriteLine("Not found");
            }

            // Now set the default options for reading 1D barcodes to search for vertical barcodes and try again
            OneDBarcodeReadOptions oneDReadOptions = reader.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeReadOptions;
            oneDReadOptions.SearchDirection = BarcodeSearchDirection.Vertical;

            // Read again
            Console.WriteLine("Reading barcodes using new options");
            barcode = reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.UPCA);

            // Show its location and data if found
            // This will find the barcode and print its information now
            if(barcode != null)
            {
               Console.WriteLine("Found a {0} barcode at {1}, data:\n{2}", barcode.Symbology, barcode.Bounds, barcode.Value);
            }
            else
            {
               Console.WriteLine("Not found");
            }
         }
      }
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
[TestMethod]
public async Task BarcodeReader_GetDefaultOptionsExample()
{
   string imageFileName = @"Assets\Barcode1.tif";
   // Create a Barcode engine
   BarcodeEngine engine = new BarcodeEngine();

   // Get the Barcode reader instance
   BarcodeReader reader = engine.Reader;

   // Load the image
   using(RasterCodecs codecs = new RasterCodecs())
   {
      StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(imageFileName);
      using(RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile)))
      {
         // Rotate the image by 90, so default option of reading horizonal barcodes will not work
         Debug.WriteLine("Rotating the image by 90 degrees");
         RotateCommand rotate = new RotateCommand(90 * 100, RotateCommandFlags.Resize, RasterColorHelper.FromKnownColor(RasterKnownColor.White));
         rotate.Run(image);

         // Read a UPCA barcode from the image using default options
         Debug.WriteLine("Reading barcodes using default options");
         BarcodeData barcode = reader.ReadBarcode(image, LeadRectHelper.Empty, BarcodeSymbology.UPCA);

         // Show its location and data if found
         // This will print out "Not found"
         if(barcode != null)
         {
            Debug.WriteLine("Found a {0} barcode at {1}, data:\n{2}", barcode.Symbology, barcode.Bounds, barcode.Value);
         }
         else
         {
            Debug.WriteLine("Not found");
         }

         // Now set the default options for reading 1D barcodes to search for vertical barcodes and try again
         OneDBarcodeReadOptions oneDReadOptions = reader.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeReadOptions;
         oneDReadOptions.SearchDirection = BarcodeSearchDirection.Vertical;

         // Read again
         Debug.WriteLine("Reading barcodes using new options");
         barcode = reader.ReadBarcode(image, LeadRectHelper.Empty, BarcodeSymbology.UPCA);

         // Show its location and data if found
         // This will find the barcode and print its information now
         if(barcode != null)
         {
            Debug.WriteLine("Found a {0} barcode at {1}, data:\n{2}", barcode.Symbology, barcode.Bounds, barcode.Value);
         }
         else
         {
            Debug.WriteLine("Not found");
         }
      }
   }
}
public void BarcodeReader_GetDefaultOptionsExample(RasterImage image)
{
   // Create a Barcode engine
   BarcodeEngine engine = new BarcodeEngine();
   // Get the Barcode reader instance
   BarcodeReader reader = engine.Reader;

   // Load the image
   RasterCodecs codecs = new RasterCodecs();

   // Rotate the image by 90, so default option of reading horizonal barcodes will not work
   Console.WriteLine("Rotating the image by 90 degrees");
   RotateCommand rotate = new RotateCommand(90 * 100, RotateCommandFlags.Resize, RasterColor.FromKnownColor(RasterKnownColor.White));
   rotate.Run(image);

   // Read a UPCA barcode from the image using default options
   Console.WriteLine("Reading barcodes using default options");
   BarcodeData barcode = reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.UPCA);

   // Show its location and data if found
   // This will print out "Not found"
   if(barcode != null)
   {
      Console.WriteLine("Found a {0} barcode at {1}, data:\n{2}", barcode.Symbology, barcode.Bounds, barcode.Value);
   }
   else
   {
      Console.WriteLine("Not found");
   }

   // Now set the default options for reading 1D barcodes to search for vertical barcodes and try again
   OneDBarcodeReadOptions oneDReadOptions = reader.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeReadOptions;
   oneDReadOptions.SearchDirection = BarcodeSearchDirection.Vertical;

   // Read again
   Console.WriteLine("Reading barcodes using new options");
   barcode = reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.UPCA);

   // Show its location and data if found
   // This will find the barcode and print its information now
   if(barcode != null)
   {
      Console.WriteLine("Found a {0} barcode at {1}, data:\n{2}", barcode.Symbology, barcode.Bounds, barcode.Value);
   }
   else
   {
      Console.WriteLine("Not found");
   }
}
Public Sub BarcodeReader_GetDefaultOptionsExample(ByVal image As RasterImage)
   ' Create a Barcode engine
   Dim engine As BarcodeEngine = New BarcodeEngine()
   ' Get the Barcode reader instance
   Dim reader As BarcodeReader = engine.Reader

   ' Load the image
   Dim codecs As RasterCodecs = New RasterCodecs()

   ' Rotate the image by 90, so default option of reading horizonal barcodes will not work
   Console.WriteLine("Rotating the image by 90 degrees")
   Dim rotate As RotateCommand = New RotateCommand(90 * 100, RotateCommandFlags.Resize, RasterColor.FromKnownColor(RasterKnownColor.White))
   rotate.Run(image)

   ' Read a UPCA barcode from the image using default options
   Console.WriteLine("Reading barcodes using default options")
   Dim barcode As BarcodeData = reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.UPCA)

   ' Show its location and data if found
   ' This will print out "Not found"
   If Not barcode Is Nothing Then
      Console.WriteLine("Found a {0} barcode at {1}, data:" & Constants.vbLf & "{2}", barcode.Symbology, barcode.Bounds, barcode.Value)
   Else
      Console.WriteLine("Not found")
   End If

   ' Now set the default options for reading 1D barcodes to search for vertical barcodes and try again
   Dim oneDReadOptions As OneDBarcodeReadOptions = TryCast(reader.GetDefaultOptions(BarcodeSymbology.UPCA), OneDBarcodeReadOptions)
   oneDReadOptions.SearchDirection = BarcodeSearchDirection.Vertical

   ' Read again
   Console.WriteLine("Reading barcodes using new options")
   barcode = reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.UPCA)

   ' Show its location and data if found
   ' This will find the barcode and print its information now
   If Not barcode Is Nothing Then
      Console.WriteLine("Found a {0} barcode at {1}, data:" & Constants.vbLf & "{2}", barcode.Symbology, barcode.Bounds, barcode.Value)
   Else
      Console.WriteLine("Not found")
   End If
End Sub
Requirements

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

See Also

Reference

BarcodeReader Class
BarcodeReader Members

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.

Leadtools.Barcode requires a Barcode Module license and unlock key. For more information, refer to: LEADTOOLS Toolkit Features