←Select platform

GetDefaultOptions Method

Summary
Gets the default read options for a specified symbology.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public BarcodeReadOptions GetDefaultOptions( 
   BarcodeSymbology symbology 
) 
- (LTBarcodeReadOptions *)defaultOptionsForSymbology:(LTBarcodeSymbology)symbology; 
public BarcodeReadOptions getDefaultOptions(BarcodeSymbology symbology) 
public: 
BarcodeReadOptions^ GetDefaultOptions(  
   BarcodeSymbology symbology 
)  
def GetDefaultOptions(self,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

This example shows how to get the default options used when reading standard linear 1D barcodes (UPC-A, UPC-E, etc) and changes them before reading the barcodes

C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Barcode; 
using Leadtools.ImageProcessing; 
 
 
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, LeadRect.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, LeadRect.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:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.IOException; 
import java.util.*; 
import java.util.concurrent.ExecutorService; 
import java.util.concurrent.Executors; 
 
import org.junit.*; 
import org.junit.Test; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.barcode.*; 
import leadtools.codecs.*; 
import leadtools.imageprocessing.*; 
import leadtools.internal.ManualResetEvent; 
 
 
public void barcodeReaderGetDefaultOptionsExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String imageFileName = combine(LEAD_VARS_IMAGES_DIR, "barcode1.tif"); 
 
   // Create a Barcode engine 
   BarcodeEngine engine = new BarcodeEngine(); 
 
   // Get the Barcode reader instance 
   BarcodeReader reader = engine.getReader(); 
 
   // Load the image 
   RasterCodecs codecs = new RasterCodecs(); 
 
   RasterImage image = codecs.load(imageFileName, 0, CodecsLoadByteOrder.BGR_OR_GRAY, 1, 1); 
 
   // Rotate the image by 90, so default option of reading horizonal barcodes will 
   // not work 
   System.out.println("Rotating the image by 90 degrees"); 
   RotateCommand rotate = new RotateCommand(90 * 100, RotateCommandFlags.RESIZE.getValue(), 
         RasterColor.fromKnownColor(RasterKnownColor.WHITE)); 
   rotate.run(image); 
 
   // Read a UPCA barcode from the image using default options 
   System.out.println("Reading barcodes using default options"); 
   BarcodeData barcode = reader.readBarcode(image, LeadRect.getEmpty(), BarcodeSymbology.UPC_A); 
 
   // Show its location and data if found 
   // This will print out "Not found" 
   if (barcode != null) 
      System.out.printf("Found a %1s barcode at %2s, data:%n%3s%n", barcode.getSymbology(), barcode.getBounds(), 
            barcode.getValue()); 
   else 
      System.out.println("Not found"); 
 
   // Now set the default options for reading 1D barcodes to search for vertical 
   // barcodes and try again 
   OneDBarcodeReadOptions oneDReadOptions = (OneDBarcodeReadOptions) reader 
         .getDefaultOptions(BarcodeSymbology.UPC_A); 
   oneDReadOptions.setSearchDirection(BarcodeSearchDirection.VERTICAL); 
 
   // Read again 
   System.out.println("Reading barcodes using new options"); 
   barcode = reader.readBarcode(image, LeadRect.getEmpty(), BarcodeSymbology.UPC_A); 
 
   // Show its location and data if found 
   // This will find the barcode and print its information now 
   if (barcode != null) 
      System.out.printf("Found a %1s barcode at %2s, data:%n%3s%n", barcode.getSymbology(), barcode.getBounds(), 
            barcode.getValue()); 
   else 
      System.out.println("Not found"); 
 
   String outputFileName = combine(LEAD_VARS_IMAGES_DIR, "Result.jpg"); 
   codecs.save(image, outputFileName, RasterImageFormat.JPEG, 0); 
 
   assertTrue("Image unsuccessfully saved to " + outputFileName, (new File(outputFileName)).exists()); 
   System.out.printf("Image successfully saved to %s%n", outputFileName); 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Barcode Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.