Example #1
0
 public Form1()
 {
     InitializeComponent();
     FormClosing += new FormClosingEventHandler(Form1_Closing);
     BarcodeQRCodeReader.InitLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ=="); // Get a license key from https://www.dynamsoft.com/customer/license/trialLicense?product=dbr
     reader      = BarcodeQRCodeReader.Create();
     capture     = new VideoCapture(0);
     isCapturing = false;
 }
Example #2
0
        static void Main(string[] args)
        {
            // Check supported platforms
            if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Console.WriteLine("Platform: Windows");
            }
            else if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                Console.WriteLine("Platform: Linux");
            }
            else if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                Console.WriteLine("Platform: macOS");
            }

            BarcodeQRCodeReader.InitLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ=="); // Get a license key from https://www.dynamsoft.com/customer/license/trialLicense?product=dbr
            BarcodeQRCodeReader?reader = null;

            try {
                reader = BarcodeQRCodeReader.Create();
                Console.WriteLine("GetVersionInfo(): " + BarcodeQRCodeReader.GetVersionInfo());

                // Refer to https://www.dynamsoft.com/barcode-reader/parameters/structure-and-interfaces-of-parameters.html?ver=latest
                reader.SetParameters("{\"Version\":\"3.0\", \"ImageParameter\":{\"Name\":\"IP1\", \"BarcodeFormatIds\":[\"BF_QR_CODE\", \"BF_ONED\"], \"ExpectedBarcodesCount\":20}}");

                Console.WriteLine("Please enter an image file: ");
                string?filename = Console.ReadLine();
                if (filename != null)
                {
                    Result[]? results = reader.DecodeFile(filename);
                    if (results != null)
                    {
                        foreach (Result result in results)
                        {
                            Console.WriteLine(result.Text);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No barcode found.");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Destroy();
                }
            }
        }
Example #3
0
        public async Task <IActionResult> Upload()
        {
            var files = Request.Form.Files;
            var path  = Path.Combine(Directory.GetCurrentDirectory(), "Upload");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            // Get a license key from https://www.dynamsoft.com/customer/license/trialLicense?product=dbr
            BarcodeQRCodeReader.InitLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==");
            BarcodeQRCodeReader?reader = BarcodeQRCodeReader.Create();
            // reader.SetParameters("{\"Version\":\"3.0\", \"ImageParameter\":{\"Name\":\"IP1\", \"BarcodeFormatIds\":[\"BF_QR_CODE\", \"BF_ONED\"], \"ExpectedBarcodesCount\":20}}");

            var output = "No barcode found.";

            foreach (var uploadFile in files)
            {
                var fileName = uploadFile.FileName;
                var filePath = Path.Combine(path, fileName);

                using (var stream = System.IO.File.Create(filePath))
                {
                    await uploadFile.CopyToAsync(stream);
                }
                if (reader != null)
                {
                    Result[]? results = reader.DecodeFile(filePath);
                    if (results != null)
                    {
                        output = "";
                        foreach (Result result in results)
                        {
                            output += result.Text + "\n";
                        }
                    }
                    else
                    {
                        output = "No barcode found.";
                    }
                }
            }

            if (reader != null)
            {
                reader.Destroy();
            }
            return(Ok(output));
        }