[SerializableAttribute()]public enum BarcodeSearchDirection
| Value | Member | Description |
|---|---|---|
| 0 | Horizontal |
Search for barcodes horizontally. This is the default behavior. |
| 1 | Vertical |
Search for barcodes vertically. |
| 2 | HorizontalAndVertical |
Search for barcodes horizontally and then vertically. |
The BarcodeReader class can search for barcodes in the image horizontally or vertically. By default, the reader will only search for the barcodes horizontally for performance reasons. You can alter this by changing the appropriate read barcode options to specify vertical or both (horizontal and vertical) search direction.
Search directions is supported for all standard 1D linear symbols and PDF417/MicroPDF417 symbols. It is not supported by Datamatrix or QR barcode symbols.
Search direction is used in the following members:
using Leadtools;using Leadtools.Codecs;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, LeadRect.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);// Check digit mode typesBarcodeReturnCheckDigit[] digits = (BarcodeReturnCheckDigit[])Enum.GetValues(typeof(BarcodeReturnCheckDigit));foreach(var digit in digits){Console.WriteLine($"Check digit modes: {digit}");}// Read againConsole.WriteLine("Reading barcodes using new options");barcodes = reader.ReadBarcodes(image, LeadRect.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;PharmaCodeBarcodeReadOptions pharmaCodeBarcodeReadOptions = reader.GetDefaultOptions(BarcodeSymbology.PharmaCode).Clone()as PharmaCodeBarcodeReadOptions;pharmaCodeBarcodeReadOptions.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, pharmaCodeBarcodeReadOptions};return readOptions;}static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";}