Barcode reading settings

Calling the decoding methods directly will use the default scanning modes and it will satisfy most of the needs. The SDK also allows you to adjust the scanning settings to optimize the scanning performance for different usage scenarios.

There are two ways to change the barcode reading settings - using the PublicRuntimeSettings Struct or template. For new developers, We recommend you to start with the PublicRuntimeSettings struct; For those who are experienced with the SDK, you may use a template which is more flexible and easier to update.

Use PublicRuntimeSettings struct to change settings

Here are some common scanning settings you might find helpful:

For more scanning settings guide, check out the How To section.

Learn more about PublicRuntimeSettings Struct.

Specify which barcode type to read

By default, the SDK will read all the supported barcode formats from the image. (See Product Overview for the full supported barcode list.)

If your full license only covers some barcode formats, you can use barcodeFormatIds to specify the barcode format(s). Check out barcodeFormatIds C++ API Reference >

For example, to enable only 1D barcode reading, you can use the following code:

C
C++
C#
Java
void *hBarcode = NULL;
char sError[512];
TextResultArray* pResult = NULL;
PublicRuntimeSettings runtimeSettings; 
hBarcode = DBR_CreateInstance();

// Initialize license prior to any decoding
//Replace "<Put your license key here>" with your own license
DBR_InitLicense(hBarcode, "<Put your license key here>");
//Set the barcode format
DBR_GetRuntimeSettings(hBarcode, &runtimeSettings);
runtimeSettings.barcodeFormatIds = 2047; // OneD barcode
DBR_UpdateRuntimeSettings(hBarcode, &runtimeSettings,sError,512);

//Replace "Put the path of your file here" with your own file path
DBR_DecodeFile(hBarcode,"<Put your file path here>","");
DBR_GetAllTextResults(hBarcode, &pResult);
DBR_FreeTextResults(&pResult);
DBR_DestroyInstance(hBarcode);
char sError[512];
TextResultArray* paryResult = NULL;
PublicRuntimeSettings* runtimeSettings = new PublicRuntimeSettings();
CBarcodeReader* reader = new CBarcodeReader();
//Initialize license prior to any decoding
//Replace "<Put your license key here>" with your own license
reader->InitLicense("<Put your license key here>");

//Set the barcode format
reader->GetRuntimeSettings(runtimeSettings);
runtimeSettings->barcodeFormatIds = 2047; //OneD barcode
reader->UpdateRuntimeSettings(runtimeSettings, sError, 512);

//Replace "<Put the path of your file here>" with your own file path
reader->DecodeFile("<Put your file path here>", "");
// If succeeds
reader->GetAllTextResults(&paryResult);
CBarcodeReader::FreeTextResults(&paryResult);
delete runtimeSettings;
delete reader;
BarcodeReader barcodeReader = new BarcodeReader();
barcodeReader.ProductKeys = "<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.BarcodeFormatIds = 2047; // OneD barcode
// update the runtime settings to the BarcodeReader object
barcodeReader.UpdateRuntimeSettings(settings);
TextResult[] aryResult = barcodeReader.DecodeFile(@"<Put your file path here>", "");
dbr.Dispose();
BarcodeReader dbr = new BarcodeReader();

// set barcodeFromatIds via PublicRuntimeSettings instance and update it to BarcodeReader instance
PublicRuntimeSettings rts = dbr.getRuntimeSettings();
rts.barcodeFormatIds =  0x7FF;// BF_ONED
dbr.updateRuntimeSettings(rts);

// Initialize license prior to any decoding
//Replace "<Put your license key here>" with your own license
dbr.initLicense("<Put your license key here>");
//Replace "Put the path of your file here" with your own file path
TextResult[] result = dbr.decodeFile("<Put your file path here>","");

Specify maximum barcode count

By default, the SDK will read as many barcodes as it can. To increase the recognition efficiency, you can use expectedBarcodesCount to specify the maximum number of barcodes to recognize according to your scenario.

C
C++
C#
Java
void *hBarcode = NULL;
char sError[512];
TextResultArray* pResult = NULL;
PublicRuntimeSettings runtimeSettings; 
hBarcode = DBR_CreateInstance();
// Initialize license prior to any decoding
//Replace "<Put your license key here>" with your own license
DBR_InitLicense(hBarcode, "<Put your license key here>");

//Set the number of barcodes to be expected 
DBR_GetRuntimeSettings(hBarcode, &runtimeSettings);
runtimeSettings.expectedBarcodesCount = 1;
DBR_UpdateRuntimeSettings(hBarcode, &runtimeSettings, sError, 512);

//Replace "<Put the path of your file here>" with your own file path
DBR_DecodeFile(hBarcode,"<Put your file path here>","");
DBR_GetAllTextResults(hBarcode, &pResult);
DBR_FreeTextResults(&pResult);
DBR_DestroyInstance(hBarcode);
char sError[512];
TextResultArray* paryResult = NULL;
PublicRuntimeSettings* runtimeSettings = new PublicRuntimeSettings();
CBarcodeReader* reader = new CBarcodeReader();
//Initialize license prior to any decoding
//Replace "<Put your license key here>" with your own license
reader->InitLicense("<Put your license key here>");
    
//Set the number of barcodes to be expected 
reader->GetRuntimeSettings(runtimeSettings);
runtimeSettings->expectedBarcodesCount = 1;
reader->UpdateRuntimeSettings(runtimeSettings, sError, 512);

//Replace "Put the path of your file here" with your own file path
reader->DecodeFile("<Put your file path here>", "");
// If succeeds
reader->GetAllTextResults(&paryResult);
CBarcodeReader::FreeTextResults(&paryResult);
delete runtimeSettings;
delete reader;
BarcodeReader barcodeReader = new BarcodeReader();
//Initialize license prior to any decoding
//Replace "<Put your license key here>" with your own license
barcodeReader.ProductKeys = "<Put your license key here>";

// get the runtime settings from the BarcodeReader object
PublicRuntimeSettings settings = barcodeReader.GetRuntimeSettings();
// limit it to decode only 1 barcode
settings.ExpectedBarcodesCount = 1; 
// update the runtime settings to the BarcodeReader object
barcodeReader.UpdateRuntimeSettings(settings);

//Replace "Put the path of your file here" with your own file path
TextResult[] aryResult = barcodeReader.DecodeFile(@"<Put your file path here>", "");
dbr.Dispose();
BarcodeReader dbr = new BarcodeReader();
PublicRuntimeSettings rts = dbr.getRuntimeSettings();

// set expected barcode count via PublicRuntimeSettings instance and update it to BarcodeReader instance
rts.expectedBarcodesCount = 10;
dbr.updateRuntimeSettings(rts);

// Initialize license prior to any decoding
//Replace "<Put your license key here>" with your own license
dbr.initLicense("<Put your license key here>");

//Replace "Put the path of your file here" with your own file path
TextResult[] result = dbr.decodeFile("<Put your file path here>","");

Specify a scan region

By default, the barcode reader will search the whole image for barcodes. 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 define an area. The following code shows how to create a template string and define the region.

C
C++
C#
Java
void *hBarcode = NULL;
char sError[512];
TextResultArray* pResult = NULL;
PublicRuntimeSettings runtimeSettings;
hBarcode = DBR_CreateInstance();
// Initialize license prior to any decoding
//Replace "<Put your license key here>" with your own license
DBR_InitLicense(hBarcode, "<Put your license key here>");

//Decode the barcodes on the left half of the image
DBR_GetRuntimeSettings(hBarcode, &runtimeSettings);
runtimeSettings.region.regionBottom = 100;
runtimeSettings.region.regionLeft = 0;
runtimeSettings.region.regionRight = 50;
runtimeSettings.region.regionTop = 0;
runtimeSettings.region.regionMeasuredByPercentage = 1; //The region is determined by percentage
DBR_UpdateRuntimeSettings(hBarcode, &runtimeSettings,sError,512);

//Replace "<Put the path of your file here>" with your own file path
DBR_DecodeFile(hBarcode,"put your file path here","");
DBR_GetAllTextResults(hBarcode, &pResult);
DBR_FreeTextResults(&pResult);
DBR_DestroyInstance(hBarcode);
char sError[512];
TextResultArray* paryResult = NULL;
PublicRuntimeSettings* runtimeSettings = new PublicRuntimeSettings();
CBarcodeReader* reader = new CBarcodeReader();
//Initialize license prior to any decoding
//Replace "<Put your license key here>" with your own license
reader->InitLicense("Put your license key here");

//Decode the barcodes on the left of the image
reader->GetRuntimeSettings(runtimeSettings);
runtimeSettings->region.regionBottom = 100;
runtimeSettings->region.regionLeft = 0;
runtimeSettings->region.regionRight = 50;
runtimeSettings->region.regionTop = 0;
runtimeSettings->region.regionMeasuredByPercentage = 1; //The region is determined by percentage
reader->UpdateRuntimeSettings(runtimeSettings, sError, 512);

//Replace "<Put the path of your file here>" with your own file path
reader->DecodeFile("<Put your file path here>", "");
// If succeeds
reader->GetAllTextResults(&paryResult);
CBarcodeReader::FreeTextResults(&paryResult);
delete runtimeSettings;
delete reader;
BarcodeReader barcodeReader = new BarcodeReader();
//Initialize license prior to any decoding
//Replace "<Put your license key here>" with your own license
barcodeReader.LicenseKeys = "<Put your license key here>";

// get the runtime settings from the BarcodeReader object
PublicRuntimeSettings settings = barcodeReader.GetRuntimeSettings();
// define the region, top 20%
settings.Region.RegionTop  = 0; 
settings.Region.RegionLeft  = 0; 
settings.Region.RegionBottom  = 20; 
settings.Region.RegionRight  = 100; 
settings.Region.RegionMeasuredByPercentage  = 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
//Replace "<Put the path of your file here>" with your own file path
TextResult[] aryResult = barcodeReader.DecodeFile(@"<Put your file path here>", string.Empty);
dbr.Dispose();
BarcodeReader dbr = new BarcodeReader();

// set region area via PublicRuntimeSettings instance and update it to BarcodeReader instance later
PublicRuntimeSettings rts = dbr.getRuntimeSettings();
//scan left half. 
//percentage base on left and top line of original image, the value refer to the percentage it pulls outward to right and bottom.  
rts.region.regionBottom = 100;
rts.region.regionLeft = 0;
rts.region.regionRight = 50;
rts.region.regionTop = 0;
rts.region.regionMeasuredByPercentage = 1; //be sure to enable measured by percentage if you wish to
dbr.updateRuntimeSettings(rts);

//Replace "<Put your license key here>" with your own license
dbr.initLicense("<Put your license key here>");

//Replace "Put the path of your file here" with your own file path
TextResult[] result = dbr.decodeFile("<Put your file path here>","");

For example:

Use a template to change settings

Besides the option of using the PublicRuntimeSettings struct, the SDK also provides InitRuntimeSettingsWithString() and InitRuntimeSettingsWithFile() APIs that enable you to use a template to control all the runtime settings. With a template, instead of writing many codes to modify the settings, you can manage all the runtime settings in a JSON file/string.

C
C++
C#
Java
void *hBarcode = NULL;
char sError[512];
TextResultArray* pResult = NULL;
hBarcode = DBR_CreateInstance();
// Initialize license prior to any decoding
//Replace "<Put your license key here>" with your own license
DBR_InitLicense(hBarcode, "<Put your license key here>");

//Use a template to modify the runtime settings
//DBR_InitRuntimeSettingsWithString() can also be used to modify the runtime settings with a json string
DBR_InitRuntimeSettingsWithFile(hBarcode, "<Put your file path here>", CM_OVERWRITE, sError, 512);

//Output runtime settings to a json file. 
//DBR_OutputLicenseToString() can also be used to output the settings to a string
DBR_OutputSettingsToFile(hBarcode, "<Put your file path here>", "runtimeSettings");

//Replace "<Put your file path here>" with your own file path
DBR_DecodeFile(hBarcode,"put your file path here","");
DBR_GetAllTextResults(hBarcode, &pResult);
DBR_FreeTextResults(&pResult);
DBR_DestroyInstance(hBarcode);


	 
char sError[512];
TextResultArray* paryResult = NULL;
CBarcodeReader* reader = new CBarcodeReader();
//Initialize license prior to any decoding
//Replace "Put your license key here" with your own license
reader->InitLicense("Put your license key here");

//Use a template to modify the runtime settings
//InitRuntimeSettingsWithString() can also be used to modify the runtime settings with a json string
reader->InitRuntimeSettingsWithFile("<Put your file path here>", CM_OVERWRITE, sError, 512);

//Output runtime settings to a json file. 
//OutputSettingsToString() can also be used to output the settings to a string
reader->OutputSettingsToFile("<Put your file path here>","currentruntime");

//Replace "Put the path of your file here" with your own file path
reader->DecodeFile("Put your file path here", "");
// If succeeds
reader->GetAllTextResults(&paryResult);
CBarcodeReader::FreeTextResults(&paryResult);
delete reader;
BarcodeReader dbr = new BarcodeReader();
string sError;
//Initialize license prior to any decoding
//Replace "Put your license key here" with your own license
dbr.ProductKeys = "<Put your license key here>";

//Use a template to modify the runtime settings
//InitRuntimeSettingsWithString() can also be used to modify the runtime settings with a json string
dbr.InitRuntimeSettingsWithFile("<Put your file path here>", EnumConflictMode.CM_OVERWRITE, out sError);

//Output runtime settings to a json file. 
//OutputSettingsToString() can also be used to output the settings to a string
dbr.OutputSettingsToFile("<Put your file path here>", "runtimesettings");

TextResult[] aryResult = dbr.DecodeFile("Put your file path here", "");
dbr.Dispose();
//to run the template, you need to change license key , file path and template json path below
//with the json template you could change runtime settings

BarcodeReader dbr = new BarcodeReader();
//Replace <Put your json template path here> with your json template path
dbr.initRuntimeSettingsWithFile("<Put your json template path here>", 1);//secord arg as conflict,1 for ignore, 2 for overwrite

// Initialize license prior to any decoding
//Replace "<Put your license key here>" with your own license
dbr.initLicense("<Put your license key here>");
//Replace <Put your file path here> with your file path
TextResult[] result = dbr.decodeFile("<Put your file path here>","");

Below is a template for your reference. To learn more about the APIs, you can check out PublicRuntimeSettings Struct.

{
   "ImageParameter" : {
      "BarcodeFormatIds" : [ "BF_ALL" ],
      "BinarizationModes" : [
         {
            "BlockSizeX" : 0,
            "BlockSizeY" : 0,
            "EnableFillBinaryVacancy" : 1,
            "ImagePreprocessingModesIndex" : -1,
            "Mode" : "BM_LOCAL_BLOCK",
            "ThreshValueCoefficient" : 10
         }
      ],
      "DeblurLevel" : 9,
      "Description" : "",
      "ExpectedBarcodesCount" : 0,
      "GrayscaleTransformationModes" : [
         {
            "Mode" : "GTM_ORIGINAL"
         }
      ],
      "ImagePreprocessingModes" : [
         {
            "Mode" : "IPM_GENERAL"
         }
      ],
      "IntermediateResultSavingMode" : {
         "Mode" : "IRSM_MEMORY"
      },
      "IntermediateResultTypes" : [ "IRT_NO_RESULT" ],
      "MaxAlgorithmThreadCount" : 4,
      "Name" : "runtimesettings",
      "PDFRasterDPI" : 300,
      "Pages" : "",
      "RegionDefinitionNameArray" : null,
      "RegionPredetectionModes" : [
         {
            "Mode" : "RPM_GENERAL"
         }
      ],
      "ResultCoordinateType" : "RCT_PIXEL",
      "ScaleDownThreshold" : 2300,
      "TerminatePhase" : "TP_BARCODE_RECOGNIZED",
      "TextFilterModes" : [
         {
            "MinImageDimension" : 65536,
            "Mode" : "TFM_GENERAL_CONTOUR",
            "Sensitivity" : 0
         }
      ],
      "TextResultOrderModes" : [
         {
            "Mode" : "TROM_CONFIDENCE"
         },
         {
            "Mode" : "TROM_POSITION"
         },
         {
            "Mode" : "TROM_FORMAT"
         }
      ],
      "TextureDetectionModes" : [
         {
            "Mode" : "TDM_GENERAL_WIDTH_CONCENTRATION",
            "Sensitivity" : 5
         }
      ],
      "Timeout" : 10000
   },
   "Version" : "3.0"
}

results matching ""

    No results matching ""