|
1 | 1 | import com.dynamsoft.dbr.*; |
2 | 2 |
|
3 | 3 | public class GeneralSettings { |
4 | | - public static void main(String[] args) { |
5 | | - try { |
6 | | - |
7 | | - // 1.Initialize license. |
| 4 | + public static void main(String[] args) { |
| 5 | + try { |
| 6 | + |
| 7 | + // 1.Initialize license. |
8 | 8 | // The string "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" here is a free public trial license. Note that network connection is required for this license to work. |
9 | 9 | // You can also request a 30-day trial license in the customer portal: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=samples&package=java |
10 | | - BarcodeReader.initLicense("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9"); |
11 | | - |
12 | | - // 2.Create an instance of Dynamsoft Barcode Reader. |
13 | | - BarcodeReader dbr = new BarcodeReader(); |
14 | | - |
15 | | - // There are two ways to configure runtime parameters. One is through PublicRuntimeSettings, the other is through parameters template. |
16 | | - // 3. General settings (including barcode format, barcode count and scan region) through PublicRuntimeSettings |
17 | | - // 3.1 Obtain current runtime settings of instance. |
18 | | - PublicRuntimeSettings sts = dbr.getRuntimeSettings(); |
19 | | - |
20 | | - // 3.2 Set the expected barcode format you want to read. |
21 | | - // The barcode format our library will search for is composed of BarcodeFormat group 1 and BarcodeFormat group 2. |
22 | | - // So you need to specify the barcode format in group 1 and group 2 individually. |
23 | | - sts.barcodeFormatIds = EnumBarcodeFormat.BF_ONED | EnumBarcodeFormat.BF_QR_CODE | EnumBarcodeFormat.BF_PDF417 | EnumBarcodeFormat.BF_DATAMATRIX; |
24 | | - sts.barcodeFormatIds_2 = EnumBarcodeFormat.BF_NULL; |
25 | | - |
26 | | - // 3.3 Set the expected barcode count you want to read. |
27 | | - sts.expectedBarcodesCount = 10; |
28 | | - |
29 | | - // 3.4 Set the ROI(region of insterest) to speed up the barcode reading process. |
30 | | - // Note: DBR supports setting coordinates by pixels or percentages. The origin of the coordinate system is the upper left corner point. |
31 | | - RegionDefinition region = new RegionDefinition(); |
32 | | - region.regionMeasuredByPercentage = 1; |
33 | | - region.regionLeft = 0; |
34 | | - region.regionRight = 100; |
35 | | - region.regionTop = 0; |
36 | | - region.regionBottom = 100; |
37 | | - sts.region = region; |
38 | | - |
39 | | - // 3.5 Apply the new settings to the instance |
40 | | - dbr.updateRuntimeSettings(sts); |
41 | | - |
42 | | - // 3. General settings (including barcode format, barcode count and scan region) through parameters template. |
43 | | - // dbr.initRuntimeSettingsWithString("{\"ImageParameter\":{\"BarcodeFormatIds\":[\"BF_ONED\",\"BF_PDF417\",\"BF_QR_CODE\",\"BF_DATAMATRIX\"],\"BarcodeFormatIds_2\":null,\"ExpectedBarcodesCount\":10,\"Name\":\"sts\",\"RegionDefinitionNameArray\":[\"region0\"]},\"RegionDefinition\":{\"Bottom\":100,\"Left\":0,\"MeasuredByPercentage\":1,\"Name\":\"region0\",\"Right\":100,\"Top\":0}}", EnumConflictMode.CM_OVERWRITE); |
44 | | - |
45 | | - // 4.Decode barcodes from an image file. |
46 | | - TextResult[] results = dbr.decodeFile("../../images/AllSupportedBarcodeTypes.png", ""); |
47 | | - |
48 | | - // 5.Output the barcode format and barcode text. |
49 | | - if (results != null && results.length > 0) { |
50 | | - for (int i = 0; i < results.length; i++) { |
51 | | - TextResult result = results[i]; |
52 | | - |
53 | | - String barcodeFormat = result.barcodeFormatString; |
54 | | - System.out.println("Barcode " + i + ":" + barcodeFormat + ","+ result.barcodeText); |
55 | | - } |
56 | | - } else { |
57 | | - System.out.println("No data detected."); |
58 | | - } |
59 | | - } catch (BarcodeReaderException ex) { |
60 | | - ex.printStackTrace(); |
61 | | - } |
62 | | - } |
| 10 | + BarcodeReader.initLicense("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9"); |
| 11 | + |
| 12 | + // 2.Create an instance of Dynamsoft Barcode Reader. |
| 13 | + BarcodeReader reader = new BarcodeReader(); |
| 14 | + |
| 15 | + // There are two ways to configure runtime parameters. One is through PublicRuntimeSettings, the other is through parameters template. |
| 16 | + // 3. General settings (including barcode format, barcode count and scan region) through PublicRuntimeSettings |
| 17 | + // 3.1 Obtain current runtime settings of instance. |
| 18 | + PublicRuntimeSettings runtimeSettings = reader.getRuntimeSettings(); |
| 19 | + |
| 20 | + // 3.2 Set the expected barcode format you want to read. |
| 21 | + // The barcode format our library will search for is composed of BarcodeFormat group 1 and BarcodeFormat group 2. |
| 22 | + // So you need to specify the barcode format in group 1 and group 2 individually. |
| 23 | + runtimeSettings.barcodeFormatIds = EnumBarcodeFormat.BF_ONED | EnumBarcodeFormat.BF_QR_CODE; |
| 24 | + runtimeSettings.barcodeFormatIds_2 = EnumBarcodeFormat_2.BF2_POSTALCODE | EnumBarcodeFormat_2.BF2_DOTCODE; |
| 25 | + |
| 26 | + // 3.3 Set the expected barcode count you want to read. |
| 27 | + runtimeSettings.expectedBarcodesCount = 10; |
| 28 | + |
| 29 | + // 3.4 Set the ROI(region of insterest) to speed up the barcode reading process. |
| 30 | + // Note: DBR supports setting coordinates by pixels or percentages. The origin of the coordinate system is the upper left corner point. |
| 31 | + RegionDefinition region = new RegionDefinition(); |
| 32 | + region.regionMeasuredByPercentage = 1; |
| 33 | + region.regionLeft = 0; |
| 34 | + region.regionRight = 100; |
| 35 | + region.regionTop = 0; |
| 36 | + region.regionBottom = 100; |
| 37 | + runtimeSettings.region = region; |
| 38 | + |
| 39 | + // 3.5 Apply the new settings to the instance |
| 40 | + reader.updateRuntimeSettings(runtimeSettings); |
| 41 | + |
| 42 | + // 3. General settings (including barcode format, barcode count and scan region) through parameters template. |
| 43 | + // reader.initRuntimeSettingsWithString("{\"ImageParameter\":{\"BarcodeFormatIds\":[\"BF_ONED\",\"BF_PDF417\",\"BF_QR_CODE\",\"BF_DATAMATRIX\"],\"BarcodeFormatIds_2\":null,\"ExpectedBarcodesCount\":10,\"Name\":\"IP1\",\"RegionDefinitionNameArray\":[\"region0\"]},\"RegionDefinition\":{\"Bottom\":100,\"Left\":0,\"MeasuredByPercentage\":1,\"Name\":\"region0\",\"Right\":100,\"Top\":0}}", EnumConflictMode.CM_OVERWRITE); |
| 44 | + |
| 45 | + // 4.Decode barcodes from an image file. |
| 46 | + TextResult[] results = reader.decodeFile("../../images/AllSupportedBarcodeTypes.png", ""); |
| 47 | + |
| 48 | + // 5.Output the barcode format and barcode text. |
| 49 | + if (results != null && results.length > 0) { |
| 50 | + System.out.println("Total barcodes found: " + results.length); |
| 51 | + for (int iIndex = 0; iIndex < results.length; iIndex++) { |
| 52 | + System.out.println("Barcode " + (iIndex + 1)); |
| 53 | + System.out.println(" Barcode Format: " + results[iIndex].barcodeFormatString); |
| 54 | + System.out.println(" Barcode Text: " + results[iIndex].barcodeText); |
| 55 | + } |
| 56 | + } else { |
| 57 | + System.out.println("No barcode detected."); |
| 58 | + } |
| 59 | + reader.destroy(); |
| 60 | + } |
| 61 | + catch (BarcodeReaderException exp) { |
| 62 | + System.out.println(exp.getMessage()); |
| 63 | + } |
| 64 | + } |
63 | 65 | } |
0 commit comments