Barcode Reading Settings

Read Barcodes with Default Mode

The general steps to use the SDK are as follows:

  1. Initialize the SDK with a license key. Typically, it only needs to be done once in the application, before calling decoding methods.

  2. Set optional barcode reading settings, such as barcode type, scanning region, etc. For new customers, you can skip this step and it will use the default settings to search for all barcode types at any angle in the whole image. For customers who want to customize the barcode reading settings, please refer to the following chapters.

  3. Perform barcode reading.

Below is the code snippet for using default settings in C#.

    BarcodeReader barcodeReader = new BarcodeReader();
    // Replace <Put your license key here> with your own license. 
    barcodeReader.LicenseKeys = "<Put your license key here>";
    TextResult[] aryResult = barcodeReader.DecodeFile(@“C:\Program Files (x86)\Dynamsoft\Barcode Reader 6.4\Images\AllSupportedBarcodeTypes.tif”, string.Empty);

If you have already installed the Dynamsoft Barcode Reader 30-day free trial, you can find the license in the "C:\Program Files (x86)\Dynamsoft\Barcode Reader {version number}\LicenseManager.exe".

Note that if you don’t pass a license to the SDK or the license has expired, the SDK will continue to function normally but the last three characters of the barcode result will be masked with “*”.

Below is a list of the default values of all public runtime barcode reading settings:

Parameter Default Value
Name N/A
AntiDamageLevel 9
BarcodeFormatIds 503317503 (All barcode formats)
ColourImageConvertMode CICM_Auto
DeblurLevel 9
EnableFillBinaryVacancy true
ExpectedBarcodesCount 0
GrayEqualizationSensitivity 0
LocalizationAlgorithmPriority "" (empty string - The library will automatically use optimized localization algorithm first)
MaxAlgorithmThreadCount 4
MaxBarcodesCount 0x7fffffff
PDFRasterDPI 300
RegionPredetectionMode RPM_Disable
ScaleDownThreshold 2300
TextFilterMode TFM_Enable
TextureDetectionSensitivity 5
Timeout 10000

Specify Which Barcode Type to Read

By default, the SDK will read the following supported barcode types from the image:

  • 1D barcodes: Code39, Code93, Code128, Codabar, ITF, EAN13, EAN8, UPCA, UPCE, INDUSTRIAL 2 OF 5;
  • 2D barcodes: QRCode, PDF417, DataMatrix, Aztec (supported since version 6.3).

If your full license only covers one or part of barcode types, you must specify which barcode type(s) the SDK should read. For example, to enable only 1D barcode reading, please use the following:

    BarcodeReader barcodeReader = new BarcodeReader();
    barcodeReader.LicenseKeys = "Put your license key here.";
    // get the runtime settings from the BarcodeReader object
    PublicRuntimeSettings settings = barcodeReader.GetRuntimeSettings();
    //only have the barcode types which you have a license for included. 
    settings.mBarcodeFormatIds = 1023; // OneD barcode
    // update the runtime settings to the BarcodeReader object
    barcodeReader.UpdateRuntimeSettings(settings);
    // setting the template name to empty will use the runtime settings you just updated

    TextResult[] aryResult = barcodeReader.DecodeFile(@“C:\Program Files (x86)\Dynamsoft\Barcode Reader 6.4\Images\AllSupportedBarcodeTypes.tif”, string.Empty);

Read a Single Barcode

By default, the SDK will read as many barcodes as it can. You can specify the maximum number of barcodes to read before decoding according to your use case. This can increase the recognition efficiency.

    // get the runtime settings from the BarcodeReader object
    PublicRuntimeSettings settings = barcodeReader.GetRuntimeSettings();
    // limit it to decode only 1 barcode
    settings.mMaxBarcodesCount = 1; 
    // update the runtime settings to the BarcodeReader object
    barcodeReader.UpdateRuntimeSettings(settings);
    // setting the template name to empty will use the runtime settings you just updated
    TextResult[] aryResult = barcodeReader.DecodeFile(@“C:\Program Files (x86)\Dynamsoft\Barcode Reader 6.4\Images\AllSupportedBarcodeTypes.tif”, string.Empty);

Read from a Region

By default, the barcode reader will search the whole image. This can lead to poor performance especially when dealing with high-resolution images. You can speed up the recognition process by restricting the scanning region.

To specify a region, you will need to create a template string/file and define the area in the RegionDefinition. For more details on RegionDefinition, please refer to this chapter.

The following function shows how to create a template string and define the region:

    public TextResult[] DecodeSpecificRegionBarcodes(string strBarcodeFilePath, int iLeft, int iTop, int iRight, int iBottom)
    {
        BarcodeReader barcodeReader = new BarcodeReader();
        barcodeReader.LicenseKeys = "Put your license key here.";
        try
        {
            //create the BarcodeReader runtime settings template string for the specific region decode.
            string strTemplateName = "TemplateName";
            string strRegionName = "RegionName";
            //create a  template json string
            string tempTemplateJsonWithRegion = "{\"ImageParameter\": {\"Name\": \"" + strTemplateName + "\",\"RegionDefinitionNameArray\": [\"" + strRegionName + "\"]},\"RegionDefinitionArray\": [{\"Name\": \"" + strRegionName + "\",\"MeasuredByPercentage\": true" + ",\"Left\":" + iLeft.ToString() + ",\"Top\":" + iTop.ToString() + ",\"Right\":" + iRight.ToString() + ",\"Bottom\":" + iBottom.ToString() + "}]}";

            // append the runtime setting template to the BarcodeReader object
            String strMsg = "";
            barcodeReader.AppendTplStringToRuntimeSettings(tempTemplateJsonWithRegion, EnumConflictMode.ECM_Overwrite, out strMsg);
            // docode the barcode file
            return barcodeReader.DecodeFile(strBarcodeFilePath, strTemplateName);
        }
        catch (BarcodeReaderException exception)
        {
            System.Console.WriteLine(exception.Message);
            Trace.WriteLine(exception.Message);
        }
        return null;
    }

For example:

// top 20%: 
DecodeSpecificRegionBarcodes(@“C:\Images\Image1.jpg”, 0, 0, 100, 20);

// bottom 20%: 
DecodeSpecificRegionBarcodes(@“C:\Images\Image2.jpg”, 0, 80, 100, 100);

// right 16%: 
DecodeSpecificRegionBarcodes(@“C:\Images\Image3.jpg”, 84, 0, 100, 100);

// left 16%: 
DecodeSpecificRegionBarcodes(@“C:\Images\Image4.jpg”, 0, 0, 16, 100);

Customize Barcode Scanning for Specific Use Case

Dynamsoft Barcode Reader provides flexible APIs for you to customize the scanning settings for different usage scenarios. You can create barcode reading templates with settings such as: barcode region, barcode count, barcode format, deblur level, anti-damage level, for best performance of your specific use case.

For more information, please refer to the Online Documentation.

results matching ""

    No results matching ""