Base class for all the barcode read options.
[SerializableAttribute()]public abstract class BarcodeReadOptions : BarcodeOptions
<TypeConverterAttribute()><SerializableAttribute()>Public MustInherit Class BarcodeReadOptionsInherits Leadtools.Barcode.BarcodeOptionsImplements System.ICloneable
@interface LTBarcodeReadOptions : LTBarcodeOptions public abstract class BarcodeReadOptions extends BarcodeOptions [TypeConverterAttribute()][SerializableAttribute()]public ref class BarcodeReadOptions abstract : public Leadtools.Barcode.BarcodeOptions, System.ICloneable
Note: In LEADTOOLS for Windows Runtime, the equivalent to this class is the IBarcodeReadOptions interface.
The BarcodeReader class contains multiple methods to read a single or multiple barcodes from an image ( Refer to the BarcodeReader.ReadBarcode and BarcodeReader.ReadBarcodes methods). For each barcode found, BarcodeReader will return an instance of BarcodeData populated with the data found in the barcode.
The BarcodeReadOptions class and its derived types is used to control the options used when reading a barcode using LEADTOOLS. You can set the options in two ways:
The BarcodeReader class contains default options for each barcode symbology (or group of common symbologies). These options can be retrieved using the BarcodeReader.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).
You can also create an instance of one of the derived BarcodeReadOptions classes and use it directly in the BarcodeReader.ReadBarcode and BarcodeReader.ReadBarcodes methods that accepts a single or array of options as an input parameter.
The BarcodeReadOptions contains the following members and features:
| Member | Description |
|---|---|
| BarcodeReadOptions.ForeColor |
Controls the barcode foreground color (color of the bars or symbols) to use when reading a barcode from a colored image. |
| BarcodeReadOptions.BackColor |
Controls the barcode background color (color of the spaces) to use when reading a barcode from a colored image. |
| BarcodeReadOptions.Load and BarcodeReadOptions.Save |
Can be used to save or load the options to/from an XML file or stream. |
| BarcodeReadOptions.GetSupportedSymbologies and BarcodeReadOptions.IsSupportedSymbology |
Can be used to get all the BarcodeSymbology's supported by this BarcodeReadOptions type or to check when a particular symbology is supported. |
BarcodeReadOptions is an abstract class and cannot be created directly, instead create one of the these derived classes:
| Read options class | Descriptions |
|---|---|
| OneDBarcodeReadOptions |
Standard 1D linear barcode options. Used when reading any of the following symbologies: EAN13, EAN8, UPCA, UPCE, Code3Of9, Code128, CodeInterleaved2Of5, Codabar, UCCEAN128, Code93, EANEXT5, EANEXT2, MSI, Code11, CodeStandard2Of5, GS1Databar, GS1DatabarLimited or GS1DatabarExpanded |
| GS1DatabarStackedBarcodeReadOptions |
GS1 Databar stacked barcode options. Used when reading GS1DatabarStacked or GS1DatabarExpandedStacked symbologies |
| FourStateBarcodeReadOptions |
4-State barcode options. Used when reading AustralianPost4State, RoyalMail4State or USPS4State symbologies |
| PostNetPlanetBarcodeReadOptions |
POSTNET/Planet barcode options. Used when reading PostNet or Planet symbologies |
| PatchCodeBarcodeReadOptions |
Patch code barcode options. Used when reading PatchCode symbology. |
| DatamatrixBarcodeReadOptions |
Datamatrix barcode options. Used when reading Datamatrix symbology. |
| MicroPDF417BarcodeReadOptions |
Micro PDF417 barcode options. Used when reading MicroPDF417 symbology. |
| PDF417BarcodeReadOptions |
PDF417 barcode options. Used when reading PDF417 symbology. |
| QRBarcodeReadOptions |
QR barcode options. Used when reading QR symbology. |
| AztecBarcodeReadOptions |
Aztec barcode options. Used when reading Aztec symbology. |
| MaxiBarcodeReadOptions |
Maxi barcode options. Used when reading Maxi symbology. |
| MicroQRBarcodeReadOptions |
MicroQR barcode options. Used when reading MicroQR symbology. |
| PharmaCodeBarcodeReadOptions |
PharmaCode barcode options. Used when reading PharmaCode symbology. |
This example sets the default barcode search options of all supported symbologies to be "Horizontal and Vertical" and then reads the barcodes from a rotated image.
using Leadtools;using Leadtools.Codecs;using Leadtools.Forms;using Leadtools.Barcode;using Leadtools.ImageProcessing;public void BarcodeReadOptions_Example(){string imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "Barcode1.tif");// Create a Barcode engineBarcodeEngine engine = new BarcodeEngine();// Get the Barcode reader instanceBarcodeReader reader = engine.Reader;// Load the imageusing (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 horizontal barcodes will not workConsole.WriteLine("Rotating the image by 90 degrees");RotateCommand rotate = new RotateCommand(90 * 100, RotateCommandFlags.Resize, RasterColor.FromKnownColor(RasterKnownColor.White));rotate.Run(image);// Read all the barcodes from the image using default optionsConsole.WriteLine("Reading barcodes using default options");BarcodeData[] barcodes = reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, null, null);// Show the number of barcodes found, should be 0 since default search direction is horizontalConsole.WriteLine("Found {0} barcodes", barcodes.Length);// Now create options to read barcodes horizontally and verticallyBarcodeReadOptions[] options = GetHorizontalAndVerticalReadBarcodeOptions(reader);// Read againConsole.WriteLine("Reading barcodes using new options");barcodes = reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, null, options);// Show the number of barcodes found, should all be read nowConsole.WriteLine("Found {0} barcodes", barcodes.Length);}}}private static BarcodeReadOptions[] GetHorizontalAndVerticalReadBarcodeOptions(BarcodeReader reader){// By default, the options read horizontal barcodes only, create an array of options capable of reading vertical barcodes// Notice, we cloned the default options in reader so we will not change the original optionsOneDBarcodeReadOptions oneDReadOptions = reader.GetDefaultOptions(BarcodeSymbology.UPCA).Clone() as OneDBarcodeReadOptions;oneDReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical;FourStateBarcodeReadOptions fourStateReadOptions = reader.GetDefaultOptions(BarcodeSymbology.USPS4State).Clone() as FourStateBarcodeReadOptions;fourStateReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical;PostNetPlanetBarcodeReadOptions postNetPlanetReadOptions = reader.GetDefaultOptions(BarcodeSymbology.PostNet).Clone() as PostNetPlanetBarcodeReadOptions;postNetPlanetReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical;GS1DatabarStackedBarcodeReadOptions gs1StackedReadOptions = reader.GetDefaultOptions(BarcodeSymbology.GS1DatabarStacked).Clone() as GS1DatabarStackedBarcodeReadOptions;gs1StackedReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical;PatchCodeBarcodeReadOptions patchCodeReadOptions = reader.GetDefaultOptions(BarcodeSymbology.PatchCode).Clone() as PatchCodeBarcodeReadOptions;patchCodeReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical;PDF417BarcodeReadOptions pdf417ReadOptions = reader.GetDefaultOptions(BarcodeSymbology.PDF417).Clone() as PDF417BarcodeReadOptions;pdf417ReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical;MicroPDF417BarcodeReadOptions microPdf417ReadOptions = reader.GetDefaultOptions(BarcodeSymbology.MicroPDF417).Clone() as MicroPDF417BarcodeReadOptions;microPdf417ReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical;// Even though this array will not contain all options, it should be enough to read all barcodes, since the version of ReadBarcodes we will use// will use the default options if an override is not passedBarcodeReadOptions[] readOptions ={oneDReadOptions, fourStateReadOptions, postNetPlanetReadOptions, gs1StackedReadOptions, patchCodeReadOptions, pdf417ReadOptions, microPdf417ReadOptions};return readOptions;}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.FormsImports Leadtools.BarcodeImports Leadtools.ImageProcessingPublic Sub BarcodeReadOptions_Example()Dim imageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Barcode1.tif")' Create a Barcode engineDim engine As New BarcodeEngine()' Get the Barcode reader instanceDim reader As BarcodeReader = engine.Reader' Load the imageUsing 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 workConsole.WriteLine("Rotating the image by 90 degrees")Dim rotate As New RotateCommand(90 * 100, RotateCommandFlags.Resize, RasterColor.FromKnownColor(RasterKnownColor.White))rotate.Run(image)' Read all the barcodes from the image using default optionsConsole.WriteLine("Reading barcodes using default options")Dim barcodes() As BarcodeData = reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, Nothing, Nothing)' Show the number of barcodes found, should be 0 since default search direction is horizontalConsole.WriteLine("Found {0} barcodes", barcodes.Length)' Now create options to read barcodes horizontally and verticallyDim options() As BarcodeReadOptions = GetHorizontalAndVerticalReadBarcodeOptions(reader)' Read againConsole.WriteLine("Reading barcodes using new options")barcodes = reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, Nothing, options)' Show the number of barcodes found, should all be read nowConsole.WriteLine("Found {0} barcodes", barcodes.Length)End UsingEnd UsingEnd SubPrivate Shared Function GetHorizontalAndVerticalReadBarcodeOptions(ByVal reader As BarcodeReader) As BarcodeReadOptions()' By default, the options read horizontal barcodes only, create an array of options capable of reading vertical barcodes' Notice, we cloned the default options in reader so we will not change the original optionsDim oneDReadOptions As OneDBarcodeReadOptions = DirectCast(reader.GetDefaultOptions(BarcodeSymbology.UPCA).Clone(), OneDBarcodeReadOptions)oneDReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVerticalDim fourStateReadOptions As FourStateBarcodeReadOptions = DirectCast(reader.GetDefaultOptions(BarcodeSymbology.USPS4State).Clone(), FourStateBarcodeReadOptions)fourStateReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVerticalDim postNetPlanetReadOptions As PostNetPlanetBarcodeReadOptions = DirectCast(reader.GetDefaultOptions(BarcodeSymbology.PostNet).Clone(), PostNetPlanetBarcodeReadOptions)postNetPlanetReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVerticalDim gs1StackedReadOptions As GS1DatabarStackedBarcodeReadOptions = DirectCast(reader.GetDefaultOptions(BarcodeSymbology.GS1DatabarStacked).Clone(), GS1DatabarStackedBarcodeReadOptions)gs1StackedReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVerticalDim patchCodeReadOptions As PatchCodeBarcodeReadOptions = DirectCast(reader.GetDefaultOptions(BarcodeSymbology.PatchCode).Clone(), PatchCodeBarcodeReadOptions)patchCodeReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVerticalDim pdf417ReadOptions As PDF417BarcodeReadOptions = DirectCast(reader.GetDefaultOptions(BarcodeSymbology.PDF417).Clone(), PDF417BarcodeReadOptions)pdf417ReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVerticalDim microPdf417ReadOptions As MicroPDF417BarcodeReadOptions = DirectCast(reader.GetDefaultOptions(BarcodeSymbology.MicroPDF417).Clone(), MicroPDF417BarcodeReadOptions)microPdf417ReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical' Even though this array will not contain all options, it should be enough to read all barcodes, since the version of ReadBarcodes we will use' will use the default options if an overriden is not passedDim readOptions() As BarcodeReadOptions ={oneDReadOptions, fourStateReadOptions, postNetPlanetReadOptions, gs1StackedReadOptions, patchCodeReadOptions, pdf417ReadOptions, microPdf417ReadOptions}Return readOptionsEnd FunctionPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
using Leadtools;using Leadtools.Codecs;using Leadtools.Forms;using Leadtools.Barcode;using Leadtools.ImageProcessing;using Leadtools.Examples;public void BarcodeReadOptions_Example(RasterImage image){// Create a Barcode engineBarcodeEngine engine = new BarcodeEngine();// Get the Barcode reader instanceBarcodeReader reader = engine.Reader;// Load the imageRasterCodecs codecs = new RasterCodecs();// Rotate the image by 90, so default option of reading horizonal barcodes will not workConsole.WriteLine("Rotating the image by 90 degrees");RotateCommand rotate = new RotateCommand(90 * 100, RotateCommandFlags.Resize, RasterColor.FromKnownColor(RasterKnownColor.White));rotate.Run(image);// Read all the barcodes from the image using default optionsConsole.WriteLine("Reading barcodes using default options");BarcodeData[] barcodes = reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, null, null);// Show the number of barcodes found, should be 0 since default search direction is horizontalConsole.WriteLine("Found {0} barcodes", barcodes.Length);// Now create options to read barcodes horizontally and verticallyBarcodeReadOptions[] options = GetHorizontalAndVerticalReadBarcodeOptions(reader);// Read againConsole.WriteLine("Reading barcodes using new options");barcodes = reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, null, options);// Show the number of barcodes found, should all be read nowConsole.WriteLine("Found {0} barcodes", barcodes.Length);}private static BarcodeReadOptions[] GetHorizontalAndVerticalReadBarcodeOptions(BarcodeReader reader){// By default, the options read horizontal barcodes only, create an array of options capable of reading vertical barcodes// Notice, we cloned the default options in reader so we will not change the original optionsOneDBarcodeReadOptions oneDReadOptions = reader.GetDefaultOptions(BarcodeSymbology.UPCA).Clone() as OneDBarcodeReadOptions;oneDReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical;FourStateBarcodeReadOptions fourStateReadOptions = reader.GetDefaultOptions(BarcodeSymbology.USPS4State).Clone() as FourStateBarcodeReadOptions;fourStateReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical;PostNetPlanetBarcodeReadOptions postNetPlanetReadOptions = reader.GetDefaultOptions(BarcodeSymbology.PostNet).Clone() as PostNetPlanetBarcodeReadOptions;postNetPlanetReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical;GS1DatabarStackedBarcodeReadOptions gs1StackedReadOptions = reader.GetDefaultOptions(BarcodeSymbology.GS1DatabarStacked).Clone() as GS1DatabarStackedBarcodeReadOptions;gs1StackedReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical;PatchCodeBarcodeReadOptions patchCodeReadOptions = reader.GetDefaultOptions(BarcodeSymbology.PatchCode).Clone() as PatchCodeBarcodeReadOptions;patchCodeReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical;PDF417BarcodeReadOptions pdf417ReadOptions = reader.GetDefaultOptions(BarcodeSymbology.PDF417).Clone() as PDF417BarcodeReadOptions;pdf417ReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical;MicroPDF417BarcodeReadOptions microPdf417ReadOptions = reader.GetDefaultOptions(BarcodeSymbology.MicroPDF417).Clone() as MicroPDF417BarcodeReadOptions;microPdf417ReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical;// Even though this array will not contain all options, it should be enough to read all barcodes, since the version of ReadBarcodes we will use// will use the default options if an overriden is not passedBarcodeReadOptions[] readOptions ={oneDReadOptions, fourStateReadOptions, postNetPlanetReadOptions, gs1StackedReadOptions, patchCodeReadOptions, pdf417ReadOptions, microPdf417ReadOptions};return readOptions;}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.FormsImports Leadtools.BarcodeImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.ColorPublic Sub BarcodeReadOptions_Example(ByVal image As RasterImage)' Create a Barcode engineDim engine As BarcodeEngine = New BarcodeEngine()' Get the Barcode reader instanceDim reader As BarcodeReader = engine.Reader' Load the imageDim codecs As RasterCodecs = New RasterCodecs()' Rotate the image by 90, so default option of reading horizonal barcodes will not workConsole.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 all the barcodes from the image using default optionsConsole.WriteLine("Reading barcodes using default options")Dim barcodes As BarcodeData() = reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, Nothing, Nothing)' Show the number of barcodes found, should be 0 since default search direction is horizontalConsole.WriteLine("Found {0} barcodes", barcodes.Length)' Now create options to read barcodes horizontally and verticallyDim options As BarcodeReadOptions() = GetHorizontalAndVerticalReadBarcodeOptions(reader)' Read againConsole.WriteLine("Reading barcodes using new options")barcodes = reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, Nothing, options)' Show the number of barcodes found, should all be read nowConsole.WriteLine("Found {0} barcodes", barcodes.Length)End SubPrivate Shared Function GetHorizontalAndVerticalReadBarcodeOptions(ByVal reader As BarcodeReader) As BarcodeReadOptions()' By default, the options read horizontal barcodes only, create an array of options capable of reading vertical barcodes' Notice, we cloned the default options in reader so we will not change the original optionsDim oneDReadOptions As OneDBarcodeReadOptions = TryCast(reader.GetDefaultOptions(BarcodeSymbology.UPCA).Clone(), OneDBarcodeReadOptions)oneDReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVerticalDim fourStateReadOptions As FourStateBarcodeReadOptions = TryCast(reader.GetDefaultOptions(BarcodeSymbology.USPS4State).Clone(), FourStateBarcodeReadOptions)fourStateReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVerticalDim postNetPlanetReadOptions As PostNetPlanetBarcodeReadOptions = TryCast(reader.GetDefaultOptions(BarcodeSymbology.PostNet).Clone(), PostNetPlanetBarcodeReadOptions)postNetPlanetReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVerticalDim gs1StackedReadOptions As GS1DatabarStackedBarcodeReadOptions = TryCast(reader.GetDefaultOptions(BarcodeSymbology.GS1DatabarStacked).Clone(), GS1DatabarStackedBarcodeReadOptions)gs1StackedReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVerticalDim patchCodeReadOptions As PatchCodeBarcodeReadOptions = TryCast(reader.GetDefaultOptions(BarcodeSymbology.PatchCode).Clone(), PatchCodeBarcodeReadOptions)patchCodeReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVerticalDim pdf417ReadOptions As PDF417BarcodeReadOptions = TryCast(reader.GetDefaultOptions(BarcodeSymbology.PDF417).Clone(), PDF417BarcodeReadOptions)pdf417ReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVerticalDim microPdf417ReadOptions As MicroPDF417BarcodeReadOptions = TryCast(reader.GetDefaultOptions(BarcodeSymbology.MicroPDF417).Clone(), MicroPDF417BarcodeReadOptions)microPdf417ReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical' Even though this array will not contain all options, it should be enough to read all barcodes, since the version of ReadBarcodes we will use' will use the default options if an overriden is not passedDim readOptions As BarcodeReadOptions() = {oneDReadOptions, fourStateReadOptions, postNetPlanetReadOptions, gs1StackedReadOptions, patchCodeReadOptions, pdf417ReadOptions, microPdf417ReadOptions}Return readOptionsEnd Function
GS1DatabarStackedBarcodeReadOptions Class
FourStateBarcodeReadOptions Class
PostNetPlanetBarcodeReadOptions Class
PatchCodeBarcodeReadOptions Class
DatamatrixBarcodeReadOptions Class
MicroPDF417BarcodeReadOptions Class
PDF417BarcodeReadOptions Class
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
