|
| 1 | +package com.java.barcode; |
| 2 | + |
| 3 | +import com.dynamsoft.dbr.*; |
| 4 | + |
| 5 | +public class App |
| 6 | +{ |
| 7 | + public void decodefile(String filename) { |
| 8 | + |
| 9 | + BarcodeReader br = null; |
| 10 | + try { |
| 11 | + BarcodeReader.initLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ=="); |
| 12 | + br = new BarcodeReader(); |
| 13 | + //Best coverage settings |
| 14 | + br.initRuntimeSettingsWithString("{\"ImageParameter\":{\"Name\":\"BestCoverage\",\"DeblurLevel\":9,\"ExpectedBarcodesCount\":512,\"ScaleDownThreshold\":100000,\"LocalizationModes\":[{\"Mode\":\"LM_CONNECTED_BLOCKS\"},{\"Mode\":\"LM_SCAN_DIRECTLY\"},{\"Mode\":\"LM_STATISTICS\"},{\"Mode\":\"LM_LINES\"},{\"Mode\":\"LM_STATISTICS_MARKS\"}],\"GrayscaleTransformationModes\":[{\"Mode\":\"GTM_ORIGINAL\"},{\"Mode\":\"GTM_INVERTED\"}]}}", EnumConflictMode.CM_OVERWRITE); |
| 15 | + //Best speed settings |
| 16 | + //br.initRuntimeSettingsWithString("{\"ImageParameter\":{\"Name\":\"BestSpeed\",\"DeblurLevel\":3,\"ExpectedBarcodesCount\":512,\"LocalizationModes\":[{\"Mode\":\"LM_SCAN_DIRECTLY\"}],\"TextFilterModes\":[{\"MinImageDimension\":262144,\"Mode\":\"TFM_GENERAL_CONTOUR\"}]}}",EnumConflictMode.CM_OVERWRITE); |
| 17 | + //Balance settings |
| 18 | + //br.initRuntimeSettingsWithString("{\"ImageParameter\":{\"Name\":\"Balance\",\"DeblurLevel\":5,\"ExpectedBarcodesCount\":512,\"LocalizationModes\":[{\"Mode\":\"LM_CONNECTED_BLOCKS\"},{\"Mode\":\"LM_STATISTICS\"}]}}",EnumConflictMode.CM_OVERWRITE); |
| 19 | + |
| 20 | + PublicRuntimeSettings runtimeSettings = br.getRuntimeSettings(); |
| 21 | + runtimeSettings.barcodeFormatIds_2 = EnumBarcodeFormat_2.BF2_DOTCODE; |
| 22 | + br.updateRuntimeSettings(runtimeSettings); |
| 23 | + } catch (Exception e) { |
| 24 | + System.out.println(e); |
| 25 | + return; |
| 26 | + } |
| 27 | + |
| 28 | + TextResult[] results = null; |
| 29 | + try { |
| 30 | + results = br.decodeFile(filename, ""); |
| 31 | + } catch (Exception e) { |
| 32 | + System.out.println("decode buffered image: " + e); |
| 33 | + } |
| 34 | + |
| 35 | + if (results != null && results.length > 0) { |
| 36 | + System.out.println("DBR result count: " + results.length); |
| 37 | + String pszTemp = null; |
| 38 | + for (TextResult result : results) { |
| 39 | + if (result.barcodeFormat != 0) { |
| 40 | + pszTemp = "Format: " + result.barcodeFormatString; |
| 41 | + } else { |
| 42 | + pszTemp = "Format: " + result.barcodeFormatString_2; |
| 43 | + } |
| 44 | + System.out.println(pszTemp); |
| 45 | + System.out.println("Text: " + result.barcodeText); |
| 46 | + System.out.println(); |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + public static void main( String[] args ) |
| 52 | + { |
| 53 | + if (args.length == 0) { |
| 54 | + System.out.println("Please add an image file"); |
| 55 | + return; |
| 56 | + } |
| 57 | + |
| 58 | + final String filename = args[0]; |
| 59 | + App test = new App(); |
| 60 | + test.decodefile(filename); |
| 61 | + } |
| 62 | +} |
0 commit comments