-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathReadAnImage.cs
59 lines (56 loc) · 2.65 KB
/
ReadAnImage.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using Dynamsoft.DBR;
using Dynamsoft.Core;
using Dynamsoft.CVR;
using Dynamsoft.License;
namespace ReadAnImage
{
internal class Program
{
static void Main(string[] args)
{
int errorCode = 1;
string errorMsg;
// Initialize license.
// You can request and extend a trial license from https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=samples&package=dotnet
// The string 'DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9' here is a free public trial license. Note that network connection is required for this license to work.
errorCode = LicenseManager.InitLicense("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9", out errorMsg);
if (errorCode != (int)EnumErrorCode.EC_OK && errorCode != (int)EnumErrorCode.EC_LICENSE_CACHE_USED)
{
Console.WriteLine("License initialization failed: ErrorCode: " + errorCode + ", ErrorString: " + errorMsg);
}
else
{
using (CaptureVisionRouter cvr = new CaptureVisionRouter())
{
string imageFile = "../../../../../../Images/GeneralBarcodes.png";
CapturedResult? result = cvr.Capture(imageFile, PresetTemplate.PT_READ_BARCODES);
if (result == null)
{
Console.WriteLine("No barcode detected.");
}
else
{
if (result.GetErrorCode() != 0)
{
Console.WriteLine("Error: " + result.GetErrorCode() + ", " + result.GetErrorString());
}
DecodedBarcodesResult? barcodesResult = result.GetDecodedBarcodesResult();
if (barcodesResult != null)
{
BarcodeResultItem[] items = barcodesResult.GetItems();
Console.WriteLine("Decoded " + items.Length + " barcodes");
foreach (BarcodeResultItem barcodeItem in items)
{
Console.WriteLine("Result " + (Array.IndexOf(items, barcodeItem) + 1));
Console.WriteLine("Barcode Format: " + barcodeItem.GetFormatString());
Console.WriteLine("Barcode Text: " + barcodeItem.GetText());
}
}
}
}
}
Console.WriteLine("Press any key to quit...");
Console.Read();
}
}
}