|
| 1 | +using System; |
| 2 | +using Dynamsoft; |
| 3 | +using Dynamsoft.DBR; |
| 4 | + |
| 5 | +namespace GeneralSettings |
| 6 | +{ |
| 7 | + class Program |
| 8 | + { |
| 9 | + static void Main(string[] args) |
| 10 | + { |
| 11 | + try |
| 12 | + { |
| 13 | + // 1. Initialize license |
| 14 | + /* |
| 15 | + // By setting organizaion ID as "200001", a 7-day trial license will be used for license verification. |
| 16 | + // Note that network connection is required for this license to work. |
| 17 | + // |
| 18 | + // When using your own license, locate the following line and specify your Organization ID. |
| 19 | + // organizationID = "200001"; |
| 20 | + // |
| 21 | + // If you don't have a license yet, you can request a trial from https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=samples&package=dotnet |
| 22 | + */ |
| 23 | + DMDLSConnectionParameters connectionInfo = BarcodeReader.InitDLSConnectionParameters(); |
| 24 | + connectionInfo.OrganizationID = "200001"; |
| 25 | + EnumErrorCode errorCode = BarcodeReader.InitLicenseFromDLS(connectionInfo, out string errorMsg); |
| 26 | + if (errorCode != EnumErrorCode.DBR_SUCCESS) |
| 27 | + { |
| 28 | + Console.WriteLine(errorMsg); |
| 29 | + } |
| 30 | + |
| 31 | + // 2. Create an instance of Barcode Reader |
| 32 | + BarcodeReader dbr = new BarcodeReader(); |
| 33 | + |
| 34 | + // 3. Configure settings |
| 35 | + |
| 36 | + // 3.1 Through PublicRuntimeSetting |
| 37 | + |
| 38 | + // 3.1.1 Call GetRuntimeSettings to get current runtime settings. |
| 39 | + PublicRuntimeSettings settings = dbr.GetRuntimeSettings(); |
| 40 | + |
| 41 | + // 3.1.2 Configure one or more specific settings |
| 42 | + // In this sample, we configure three settings: |
| 43 | + // try to finnd PDF 417 and DotCode |
| 44 | + settings.BarcodeFormatIds = (int)EnumBarcodeFormat.BF_PDF417; |
| 45 | + settings.BarcodeFormatIds_2 = (int)EnumBarcodeFormat_2.BF2_DOTCODE; |
| 46 | + // try to find 2 barcodes |
| 47 | + settings.ExpectedBarcodesCount = 2; |
| 48 | + // try to find barcodes in the lower part of the image |
| 49 | + settings.Region.RegionLeft = 0; |
| 50 | + settings.Region.RegionRight = 100; |
| 51 | + settings.Region.RegionTop = 50; |
| 52 | + settings.Region.RegionBottom = 100; |
| 53 | + settings.Region.RegionMeasuredByPercentage = 1; |
| 54 | + |
| 55 | + // 3.1.3 Call UpdateRuntimeSettings to apply above settings |
| 56 | + dbr.UpdateRuntimeSettings(settings); |
| 57 | + |
| 58 | + // 3.2 Through JSON template |
| 59 | + //string errorMessage; |
| 60 | + //dbr.InitRuntimeSettingsWithString("{\"ImageParameter\":{\"Name\":\"S1\",\"RegionDefinitionNameArray\":[\"R1\"]},\"RegionDefinition\":{\"Name\":\"R1\",\"BarcodeFormatIds\":[\"BF_PDF417\"],\"BarcodeFormatIds_2\":[\"BF2_POSTALCODE\"],\"ExpectedBarcodesCount\":2,\"Left\":0,\"Right\":100,\"Top\":50,\"Bottom\":100,\"MeasuredByPercentage\":1}}", EnumConflictMode.CM_IGNORE, out errorMessage); |
| 61 | + |
| 62 | + |
| 63 | + try |
| 64 | + { |
| 65 | + TextResult[] results = null; |
| 66 | + |
| 67 | + // 4. Read barcode from an image file |
| 68 | + results = dbr.DecodeFile("../../../../images/AllSupportedBarcodeTypes.png", ""); |
| 69 | + |
| 70 | + if (results != null && results.Length > 0) |
| 71 | + { |
| 72 | + for (int i = 0; i < results.Length; ++i) |
| 73 | + { |
| 74 | + Console.WriteLine("Result " + (i + 1).ToString() + ":"); |
| 75 | + |
| 76 | + // 5. Get format of each barcode |
| 77 | + if (results[i].BarcodeFormat != EnumBarcodeFormat.BF_NULL) |
| 78 | + Console.WriteLine(" Barcode Format: " + results[i].BarcodeFormatString); |
| 79 | + else |
| 80 | + Console.WriteLine(" Barcode Format: " + results[i].BarcodeFormatString_2); |
| 81 | + |
| 82 | + // 6. Get text result of each barcode |
| 83 | + Console.WriteLine(" Barcode Text: " + results[i].BarcodeText); |
| 84 | + } |
| 85 | + } |
| 86 | + else |
| 87 | + { |
| 88 | + Console.WriteLine("No barcode detected."); |
| 89 | + } |
| 90 | + } |
| 91 | + catch (BarcodeReaderException exp) |
| 92 | + { |
| 93 | + Console.WriteLine(exp.Message); |
| 94 | + } |
| 95 | + } |
| 96 | + catch (Exception exp) |
| 97 | + { |
| 98 | + Console.WriteLine(exp.Message); |
| 99 | + } |
| 100 | + Console.WriteLine("Press any key to quit..."); |
| 101 | + Console.ReadKey(); |
| 102 | + } |
| 103 | + } |
| 104 | +} |
0 commit comments