←Select platform

PharmaCodeBarcodeReadOptions Class

Summary
Contains the extra options to use when reading PharmaCode barcodes.
Syntax
C#
Objective-C
C++/CLI
Python
[SerializableAttribute()] 
public class PharmaCodeBarcodeReadOptions : BarcodeReadOptions 
@interface LTPharmaCodeBarcodeReadOptions : LTBarcodeReadOptions 
[TypeConverterAttribute()] 
[SerializableAttribute()] 
public ref class PharmaCodeBarcodeReadOptions : public BarcodeReadOptions, System.ICloneable   
class PharmaCodeBarcodeReadOptions(BarcodeReadOptions): 
Remarks

The PharmaCodeBarcodeReadOptions class is used to control the options when reading PharmaCode barcodes using LEADTOOLS. 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 BarcodeSymbology.PharmaCode

Change the members of the returned PharmaCodeBarcodeReadOptions by casting it from BarcodeReadOptions to PharmaCodeBarcodeReadOptions.

You can also create an instance of the PharmaCodeBarcodeReadOptions class and use it directly in the BarcodeReader.ReadBarcode and BarcodeReader.ReadBarcodes methods that accept a single or array of options as an input parameter.

The base 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

This class overrides the base class method to return an array containing the following symbologies: BarcodeSymbology.PharmaCode

In addition to the features and members, the PharmaCodeBarcodeReadOptions contains these PharmaCode barcode specific features:

Member Description
SearchDirection

The direction to use when searching for barcodes (horizontal, vertical or both)

Example

This example writes a PharmaCode barcode to an image and then reads it back.

C#
Java
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 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 horizontal 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 all the barcodes from the image using default options 
         Console.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 horizontal 
         Console.WriteLine("Found {0} barcodes", barcodes.Length); 
 
         // Now create options to read barcodes horizontally and vertically 
         BarcodeReadOptions[] options = GetHorizontalAndVerticalReadBarcodeOptions(reader); 
 
         // Check digit mode types 
         BarcodeReturnCheckDigit[] digits = (BarcodeReturnCheckDigit[])Enum.GetValues(typeof(BarcodeReturnCheckDigit)); 
         foreach(var digit in digits) 
         { 
            Console.WriteLine($"Check digit modes: {digit}"); 
         } 
 
         // Read again 
         Console.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 now 
         Console.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 options 
 
   OneDBarcodeReadOptions 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 passed 
   BarcodeReadOptions[] readOptions = 
   { 
   oneDReadOptions, fourStateReadOptions, postNetPlanetReadOptions, gs1StackedReadOptions, patchCodeReadOptions, pdf417ReadOptions, microPdf417ReadOptions, pharmaCodeBarcodeReadOptions 
 }; 
 
   return readOptions; 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.IOException; 
 
import javax.sound.sampled.AudioFileFormat.Type; 
 
import org.junit.*; 
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.*; 
 
 
public void barcodeReadOptionsExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS22\\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 horizontal 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 all the barcodes from the image using default options 
   System.out.println("Reading barcodes using default options"); 
   BarcodeData[] barcodes = reader.readBarcodes(image, LeadRect.getEmpty(), 0, null, null); 
 
   // Show the number of barcodes found, should be 0 since default search direction 
   // is horizontal 
   System.out.println(String.format("Found %s barcodes", barcodes.length)); 
 
   // Now create options to read barcodes horizontally and vertically 
   BarcodeReadOptions[] options = GetHorizontalAndVerticalReadBarcodeOptions(reader); 
 
   // Check digit mode types 
   BarcodeReturnCheckDigit[] digits = BarcodeReturnCheckDigit.values(); 
   for (var digit : digits) { 
      System.out.println(String.format("Check digit modes: %s", digit)); 
   } 
 
   // Read again 
   System.out.println("Reading barcodes using new options"); 
   barcodes = reader.readBarcodes(image, LeadRect.getEmpty(), 0, null, options); 
 
   // Show the number of barcodes found, should all be read now 
   System.out.println(String.format("Found %s barcodes", barcodes.length)); 
 
   codecs.dispose(); 
   image.dispose(); 
} 
 
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 options 
 
   OneDBarcodeReadOptions oneDReadOptions = (OneDBarcodeReadOptions) reader.getDefaultOptions(BarcodeSymbology.UPC_A) 
         .clone(); // fix as part, go back to other times u had it 
   oneDReadOptions.setSearchDirection(BarcodeSearchDirection.HORIZONTAL_AND_VERTICAL); 
 
   FourStateBarcodeReadOptions fourStateReadOptions = (FourStateBarcodeReadOptions) reader 
         .getDefaultOptions(BarcodeSymbology.USPS_4STATE).clone(); 
   fourStateReadOptions.setSearchDirection(BarcodeSearchDirection.HORIZONTAL_AND_VERTICAL); 
 
   PostNetPlanetBarcodeReadOptions postNetPlanetReadOptions = (PostNetPlanetBarcodeReadOptions) reader 
         .getDefaultOptions(BarcodeSymbology.POST_NET).clone(); 
   postNetPlanetReadOptions.setSearchDirection(BarcodeSearchDirection.HORIZONTAL_AND_VERTICAL); 
 
   GS1DatabarStackedBarcodeReadOptions gs1StackedReadOptions = (GS1DatabarStackedBarcodeReadOptions) reader 
         .getDefaultOptions(BarcodeSymbology.GS1_DATA_BAR_STACKED).clone(); 
   gs1StackedReadOptions.setSearchDirection(BarcodeSearchDirection.HORIZONTAL_AND_VERTICAL); 
 
   PatchCodeBarcodeReadOptions patchCodeReadOptions = (PatchCodeBarcodeReadOptions) reader 
         .getDefaultOptions(BarcodeSymbology.PATCH_CODE).clone(); 
   patchCodeReadOptions.setSearchDirection(BarcodeSearchDirection.HORIZONTAL_AND_VERTICAL); 
 
   PDF417BarcodeReadOptions pdf417ReadOptions = (PDF417BarcodeReadOptions) reader 
         .getDefaultOptions(BarcodeSymbology.PDF417).clone(); 
   pdf417ReadOptions.setSearchDirection(BarcodeSearchDirection.HORIZONTAL_AND_VERTICAL); 
 
   MicroPDF417BarcodeReadOptions microPdf417ReadOptions = (MicroPDF417BarcodeReadOptions) reader 
         .getDefaultOptions(BarcodeSymbology.MICRO_PDF417).clone(); 
   microPdf417ReadOptions.setSearchDirection(BarcodeSearchDirection.HORIZONTAL_AND_VERTICAL); 
 
   PharmaCodeBarcodeReadOptions pharmaCodeBarcodeReadOptions = (PharmaCodeBarcodeReadOptions) reader 
         .getDefaultOptions(BarcodeSymbology.PHARMA_CODE).clone(); 
   pharmaCodeBarcodeReadOptions.setSearchDirection(BarcodeSearchDirection.HORIZONTAL_AND_VERTICAL); 
 
   // 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 
   // the default options if an override is not passed 
   BarcodeReadOptions[] readOptions = { 
         oneDReadOptions, fourStateReadOptions, postNetPlanetReadOptions, gs1StackedReadOptions, 
         patchCodeReadOptions, pdf417ReadOptions, microPdf417ReadOptions, pharmaCodeBarcodeReadOptions 
   }; 
 
   return readOptions; 
} 
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.