Thanks for downloading Dynamsoft Barcode Reader Package!
Your download will start shortly. If your download does not begin, click here to retry.
To install Dynamsoft Barcode Reader Java SDK on your development machine, you can download the SDK from the Dynamsoft website and unzip the dbr-java-{version number}.zip
The items under the dbr-java-{version number} folder: Dynamsoft Barcode Reader\samples contains the source code of sample application. Dynamsoft Barcode Reader\documents contains the API Reference, the Developer’s Guide, and legal notices. Dynamsoft Barcode Reader\lib\dynamsoft-barcodereader-{version number}.jar is the library file.
You can add Dynamsoft Barcode Reader as the dependency to pom.xml like this:
<dependencies>
<dependency>
<groupId>com.dynamsoft</groupId>
<artifactId>dbr</artifactId>
<version>7.6.0</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>dbr</id>
<url>https://download2.dynamsoft.com/maven/dbr/jar</url>
</repository>
</repositories>
import com.dynamsoft.barcode.*;
public class HelloDBR {
public static void main(String[] args) {
try {
BarcodeReader dbr = new BarcodeReader();
dbr.initLicense("<Put your license key here>");
TextResult[] result = dbr.decodeFile("<your image file full path>", "");
String output = "";
for(int i =0; i<result.length;i++){
output += "Barcode Text: ";
output += result[i].barcodeText + "\n\n";
}
System.out.println(output);
} catch (Exception ex) {
}
}
}
Please update <your image file full path>
and <your license key here>
in the code accordingly.
The SDK provides multiple decoding methods that support reading barcodes from different sources, including static images, video stream, files in memory, base64 string, bitmap, etc. Here is a list of all decoding methods:
You can find more samples in more programming languages at Code Gallery or Github Repositories.
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 class or template. For new developers, We recommend you to start with the PublicRuntimeSettings class; For those who are experienced with the SDK, you may use a template which is more flexible and easier to update.
PublicRuntimeSettings
class to Change SettingsHere are some common scanning settings you might find helpful:
For more scanning settings guide, check out the How To section.
By default, the SDK will read all the supported barcode formats except Postal Codes and DotCode 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
and BarcodeFormatIds_2
to specify the barcode format(s). Check out BarcodeFormat
and BarcodeFormat_2
.
For example, to enable only 1D barcode reading, you can use the following code:
BarcodeReader dbr = new BarcodeReader();
dbr.initLicense("<Put your license key here>"); //Replace "<Put your license key here>" with your own license
// Set barcodeFormatIds via PublicRuntimeSettings instance and update it to BarcodeReader instance
PublicRuntimeSettings runtimeSettings = dbr.getRuntimeSettings();
runtimeSettings.barcodeFormatIds = 0x7FF;// OneD barcode
dbr.updateRuntimeSettings(runtimeSettings);
// Replace "<Put the path of your file here>" with your own file path
TextResult[] result = dbr.decodeFile("<Put your file path here>","");
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.
BarcodeReader dbr = new BarcodeReader();
dbr.initLicense("<Put your license key here>"); //Replace "<Put your license key here>" with your own license
PublicRuntimeSettings rts = dbr.getRuntimeSettings();
rts.expectedBarcodesCount = 10;
dbr.updateRuntimeSettings(rts);
//Replace "<Put the path of your file here>" with your own file path
TextResult[] result = dbr.decodeFile("<Put your file path here>","");
reader.destroy();
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.
BarcodeReader dbr = new BarcodeReader();
dbr.initLicense("<Put your license key here>"); //Replace "<Put your license key here>" with your own license
PublicRuntimeSettings runtimeSettings = dbr.getRuntimeSettings();
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(runtimeSettings);
//Replace "<Put the path of your file here>" with your own file path
TextResult[] result = dbr.decodeFile("<Put your file path here>","");
reader.destroy();
Besides the option of using the PublicRuntimeSettings class, 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.
BarcodeReader dbr = new BarcodeReader();
dbr.initLicense("<Put your license key here>"); //Replace "<Put your license key here>" with your own license
br.initRuntimeSettingsWithFile("<put your json file here>", EnumConflictMode.CM_OVERWRITE);
//Replace "<Put the path of your file here>" with your own file path
TextResult[] result = dbr.decodeFile("<Put your file path here>","");
reader.destroy();
Below is a template for your reference. To learn more about the APIs, you can check out PublicRuntimeSettings
Class.
{
"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"
}
version 7.6.0