public static void RenderImageAsync(VideoCollection videoCollection, BarcodeConfig file, IProgress <ProgressWrapper> progress, CancellationToken cancellationToken)
        {
            if (File.Exists(file.Barcode_Standard.FullOutputFile))
            {
                _logger = LogManager.GetCurrentClassLogger();
                _logger.Warn($"Image {file.Barcode_Standard.FullOutputFile} already exists, skipping image creation");

                return;
            }

            var bmp = new Bitmap(file.OutputWidth, file.OutputHeight);

            using (Graphics graph = Graphics.FromImage(bmp))
            {
                double frame     = 0;
                double frameJump = videoCollection.Data.Colours.Count / (double)file.OutputWidth;

                for (var i = 0; i < file.OutputWidth; i++)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    frame = frame + frameJump;

                    Rectangle imageSize = new Rectangle(i, 0, i, file.OutputHeight);

                    graph.FillRectangle(new SolidBrush(ColorTranslator.FromHtml(videoCollection.Data.Colours.First(c => c.Frame == Convert.ToInt32(frame)).Hex)), imageSize);

                    progress.Report(new ProgressWrapper(file.OutputWidth, i + 1, ProcessType.RenderImage));
                }
            }

            bmp.Save(file.Barcode_Standard.FullOutputFile, ImageFormat.Jpeg);
        }
Exemplo n.º 2
0
 public CameraBarcodeScanner(Context context)
 {
     this.Context = context;
     BarcodeConfig.MWB_setDirection(BarcodeConfig.MWB_SCANDIRECTION_HORIZONTAL | BarcodeConfig.MWB_SCANDIRECTION_VERTICAL);
     BarcodeConfig.MWB_setActiveCodes(BarcodeConfig.MWB_CODE_MASK_39 | BarcodeConfig.MWB_CODE_MASK_128 | BarcodeConfig.MWB_CODE_MASK_EANUPC | BarcodeConfig.MWB_CODE_MASK_QR);
     BarcodeConfig.MWB_setLevel(2);
 }
Exemplo n.º 3
0
        public static void glassDecoderInit()
        {
            Console.WriteLine("Decoder initialization");
            //register your copy of library with givern user/password
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_39, "username", "key");
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_93, "username", "key");
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_25, "username", "key");
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_128, "username", "key");
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_AZTEC, "username", "key");
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_DM, "username", "key");
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_EANUPC, "username", "key");
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_QR, "username", "key");
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_PDF, "username", "key");
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_RSS, "username", "key");
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_CODABAR, "username", "key");
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_DOTCODE, "username", "key");


            BarcodeConfig.MWB_setActiveCodes(BarcodeConfig.MWB_CODE_MASK_DM | BarcodeConfig.MWB_CODE_MASK_QR);


            BarcodeConfig.MWB_setDirection(BarcodeConfig.MWB_SCANDIRECTION_HORIZONTAL);

            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_25, RECT_LANDSCAPE_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_39, RECT_LANDSCAPE_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_93, RECT_LANDSCAPE_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_128, RECT_LANDSCAPE_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_AZTEC, RECT_LANDSCAPE_2D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_DM, RECT_LANDSCAPE_2D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_EANUPC, RECT_LANDSCAPE_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_PDF, RECT_LANDSCAPE_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_QR, RECT_LANDSCAPE_2D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_RSS, RECT_LANDSCAPE_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_CODABAR, RECT_LANDSCAPE_1D);


            // set decoder effort level (1 - 5)
            // for live scanning scenarios, a setting between 1 to 3 will suffice
            // levels 4 and 5 are typically reserved for batch scanning
            BarcodeConfig.MWB_setLevel(2);
            //get and print Library version
            int    ver        = BarcodeConfig.MWB_getLibVersion();
            int    v1         = (ver >> 16);
            int    v2         = (ver >> 8) & 0xff;
            int    v3         = (ver & 0xff);
            String libVersion = v1.ToString() + "." + v2.ToString() + "." + v3.ToString();

            Console.WriteLine("Lib version: " + libVersion);
        }
Exemplo n.º 4
0
 public BarcodeDecoder(IOptions <BarcodeConfig> optionsAccessor, IBitmapReader bitmapReader)
 {
     _config       = optionsAccessor.Value;
     _bitmapReader = bitmapReader;
     barcodeReader = new ZXing.BarcodeReader
     {
         AutoRotate  = true,
         TryInverted = true,
         Options     = new DecodingOptions
         {
             TryHarder       = true,
             PossibleFormats = _config.PossibleFormats
         }
     };
     results = new List <DecodeResult>();
 }
Exemplo n.º 5
0
        public void test_spanish_barcode()
        {
            var cfg = new BarcodeConfig()
            {
                Name          = "Spain",
                Length        = 18,
                HasCheckDigit = true,
                //iso, ty, br, voucher
                Template   = "{0:000}{1:00}{2:00000}{3:0000000}",
                Sample     = "724 21 43101 4876719 9",
                CountryID  = new Tuple <int, int>(0, 3),
                BuzType    = new Tuple <int, int>(3, 2),
                RetailerID = new Tuple <int, int>(5, 5),
                VoucherID  = new Tuple <int, int>(10, 7),
            };
            BarcodeData data = null;

            cfg.ParseBarcode("724214310148767199", ref data);
        }
Exemplo n.º 6
0
        public void Test_BarcodeConfigigurations()
        {
            var bg = new BarcodeConfig()
            {
                Name          = "Default",
                Length        = 19,
                HasCheckDigit = true,
                //iso, ty, br, voucher
                Template   = "{0:000}{1:00}{2:000000}{3:00000000}",
                Sample     = "826 20 188025 33359669 9",
                CountryID  = new Tuple <int, int>(0, 3),
                BuzType    = new Tuple <int, int>(3, 2),
                RetailerID = new Tuple <int, int>(5, 6),
                VoucherID  = new Tuple <int, int>(11, -1),
            };
            BarcodeData data = null;

            bg.ParseBarcode("001977684056100353", ref data);
        }
Exemplo n.º 7
0
        private void Initialize(ScanningConfigCollection config)
        {
            if ((config == null) || (config.Count == 0))
            {
                throw new Exception("No keys found for initializations.");
            }
            int codes = 0;

            foreach (var c in config)
            {
                InitConfig(c);
                codes |= c.Code;
            }
            //  configure which codes to search for - less codes = faster
            BarcodeConfig.MWB_setActiveCodes(codes);
            // search in both directions
            BarcodeConfig.MWB_setDirection(BarcodeConfig.MWB_SCANDIRECTION_HORIZONTAL | BarcodeConfig.MWB_SCANDIRECTION_VERTICAL);

            // set decoder effort level (1 - 5)
            // for live scanning scenarios, a setting between 1 to 3 will suffice
            // levels 4 and 5 are typically reserved for batch scanning
            BarcodeConfig.MWB_setLevel(2);
        }
Exemplo n.º 8
0
 private void InitConfig(ScanningConfig config)
 {
     //  register the plugin - must be done foreach not using the full bitmask
     if (config.Code == BarcodeConfig.MWB_CODE_MASK_39)
     {
         BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_39, config.UserName, config.Key);
         BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_39, RECT_FULL_1D);
     }
     else if (config.Code == BarcodeConfig.MWB_CODE_MASK_93)
     {
         BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_93, config.UserName, config.Key);
         BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_93, RECT_FULL_1D);
     }
     else if (config.Code == BarcodeConfig.MWB_CODE_MASK_25)
     {
         BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_25, config.UserName, config.Key);
         BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_25, RECT_FULL_1D);
     }
     else if (config.Code == BarcodeConfig.MWB_CODE_MASK_128)
     {
         BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_128, config.UserName, config.Key);
         BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_128, RECT_FULL_1D);
     }
     else if (config.Code == BarcodeConfig.MWB_CODE_MASK_AZTEC)
     {
         BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_AZTEC, config.UserName, config.Key);
         BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_AZTEC, RECT_FULL_2D);
     }
     else if (config.Code == BarcodeConfig.MWB_CODE_MASK_DM)
     {
         BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_DM, config.UserName, config.Key);
         BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_DM, RECT_FULL_2D);
     }
     else if (config.Code == BarcodeConfig.MWB_CODE_MASK_EANUPC)
     {
         BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_EANUPC, config.UserName, config.Key);
         BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_EANUPC, RECT_FULL_1D);
     }
     else if (config.Code == BarcodeConfig.MWB_CODE_MASK_QR)
     {
         BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_QR, config.UserName, config.Key);
         BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_QR, RECT_FULL_2D);
     }
     else if (config.Code == BarcodeConfig.MWB_CODE_MASK_PDF)
     {
         BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_PDF, config.UserName, config.Key);
         BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_PDF, RECT_FULL_1D);
     }
     else if (config.Code == BarcodeConfig.MWB_CODE_MASK_RSS)
     {
         BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_RSS, config.UserName, config.Key);
         BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_RSS, RECT_FULL_1D);
     }
     else if (config.Code == BarcodeConfig.MWB_CODE_MASK_CODABAR)
     {
         BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_CODABAR, config.UserName, config.Key);
         BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_CODABAR, RECT_FULL_1D);
     }
     else if (config.Code == BarcodeConfig.MWB_CODE_MASK_DOTCODE)
     {
         BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_DOTCODE, config.UserName, config.Key);
         BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_DOTCODE, RECT_DOTCODE);
     }
     else if (config.Code == BarcodeConfig.MWB_CODE_MASK_11)
     {
         BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_11, config.UserName, config.Key);
         BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_11, RECT_FULL_1D);
     }
     else if (config.Code == BarcodeConfig.MWB_CODE_MASK_MSI)
     {
         BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_MSI, config.UserName, config.Key);
         BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_MSI, RECT_FULL_1D);
     }
 }
Exemplo n.º 9
0
        public static void customDecoderInit()
        {
            Console.WriteLine("Decoder initialization");
            //register your copy of library with givern user/password
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_39, "username", "key");
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_93, "username", "key");
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_25, "username", "key");
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_128, "username", "key");
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_AZTEC, "username", "key");
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_DM, "username", "key");
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_EANUPC, "username", "key");
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_QR, "username", "key");
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_PDF, "username", "key");
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_RSS, "username", "key");
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_CODABAR, "username", "key");
            BarcodeConfig.MWB_registerCode(BarcodeConfig.MWB_CODE_MASK_DOTCODE, "username", "key");


            // choose code type or types you want to search for

            // Our sample app is configured by default to search all supported barcodes...
            BarcodeConfig.MWB_setActiveCodes(BarcodeConfig.MWB_CODE_MASK_25 |
                                             BarcodeConfig.MWB_CODE_MASK_39 |
                                             BarcodeConfig.MWB_CODE_MASK_93 |
                                             BarcodeConfig.MWB_CODE_MASK_128 |
                                             BarcodeConfig.MWB_CODE_MASK_AZTEC |
                                             BarcodeConfig.MWB_CODE_MASK_DM |
                                             BarcodeConfig.MWB_CODE_MASK_EANUPC |
                                             BarcodeConfig.MWB_CODE_MASK_PDF |
                                             BarcodeConfig.MWB_CODE_MASK_QR |
                                             BarcodeConfig.MWB_CODE_MASK_CODABAR |
                                             BarcodeConfig.MWB_CODE_MASK_RSS);

            // But for better performance, only activate the symbologies your application requires...
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_25 );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_39 );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_93 );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_128 );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_AZTEC );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_DM );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_EANUPC );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_PDF );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_QR );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_RSS );
            //BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_DOTCODE );


            // Our sample app is configured by default to search both directions...
            BarcodeConfig.MWB_setDirection(BarcodeConfig.MWB_SCANDIRECTION_HORIZONTAL | BarcodeConfig.MWB_SCANDIRECTION_VERTICAL);
            // set the scanning rectangle based on scan direction(format in pct: x, y, width, height)
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_25, RECT_FULL_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_39, RECT_FULL_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_93, RECT_FULL_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_128, RECT_FULL_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_AZTEC, RECT_FULL_2D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_DM, RECT_FULL_2D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_EANUPC, RECT_FULL_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_PDF, RECT_FULL_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_QR, RECT_FULL_2D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_RSS, RECT_FULL_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_CODABAR, RECT_FULL_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_DOTCODE, RECT_DOTCODE);


            // But for better performance, set like this for PORTRAIT scanning...
            // BarcodeConfig.MWB_setDirection(BarcodeConfig.MWB_SCANDIRECTION_VERTICAL);
            // set the scanning rectangle based on scan direction(format in pct: x, y, width, height)
            // BarcodeConfig.MWB_setScanningRect(BarcodeConfig.MWB_CODE_MASK_25,     RECT_PORTRAIT_1D);
            // BarcodeConfig.MWB_setScanningRect(BarcodeConfig.MWB_CODE_MASK_39,     RECT_PORTRAIT_1D);
            // BarcodeConfig.MWB_setScanningRect(BarcodeConfig.MWB_CODE_MASK_93,     RECT_PORTRAIT_1D);
            // BarcodeConfig.MWB_setScanningRect(BarcodeConfig.MWB_CODE_MASK_128,    RECT_PORTRAIT_1D);
            // BarcodeConfig.MWB_setScanningRect(BarcodeConfig.MWB_CODE_MASK_AZTEC,  RECT_PORTRAIT_2D);
            // BarcodeConfig.MWB_setScanningRect(BarcodeConfig.MWB_CODE_MASK_DM,     RECT_PORTRAIT_2D);
            // BarcodeConfig.MWB_setScanningRect(BarcodeConfig.MWB_CODE_MASK_EANUPC, RECT_PORTRAIT_1D);
            // BarcodeConfig.MWB_setScanningRect(BarcodeConfig.MWB_CODE_MASK_PDF,    RECT_PORTRAIT_1D);
            // BarcodeConfig.MWB_setScanningRect(BarcodeConfig.MWB_CODE_MASK_QR,     RECT_PORTRAIT_2D);
            // BarcodeConfig.MWB_setScanningRect(BarcodeConfig.MWB_CODE_MASK_RSS,    RECT_PORTRAIT_1D);
            // BarcodeConfig.MWB_setScanningRect(BarcodeConfig.MWB_CODE_MASK_CODABAR,RECT_PORTRAIT_1D);

            // or like this for LANDSCAPE scanning - Preferred for dense or wide codes...
            // BarcodeConfig.MWB_setDirection(BarcodeConfig.MWB_SCANDIRECTION_HORIZONTAL);
            // set the scanning rectangle based on scan direction(format in pct: x, y, width, height)
            // BarcodeConfig.MWB_setScanningRect(BarcodeConfig.MWB_CODE_MASK_25,     RECT_LANDSCAPE_1D);
            // BarcodeConfig.MWB_setScanningRect(BarcodeConfig.MWB_CODE_MASK_39,     RECT_LANDSCAPE_1D);
            // BarcodeConfig.MWB_setScanningRect(BarcodeConfig.MWB_CODE_MASK_93,     RECT_LANDSCAPE_1D);
            // BarcodeConfig.MWB_setScanningRect(BarcodeConfig.MWB_CODE_MASK_128,    RECT_LANDSCAPE_1D);
            // BarcodeConfig.MWB_setScanningRect(BarcodeConfig.MWB_CODE_MASK_AZTEC,  RECT_LANDSCAPE_2D);
            // BarcodeConfig.MWB_setScanningRect(BarcodeConfig.MWB_CODE_MASK_DM,     RECT_LANDSCAPE_2D);
            // BarcodeConfig.MWB_setScanningRect(BarcodeConfig.MWB_CODE_MASK_EANUPC, RECT_LANDSCAPE_1D);
            // BarcodeConfig.MWB_setScanningRect(BarcodeConfig.MWB_CODE_MASK_PDF,    RECT_LANDSCAPE_1D);
            // BarcodeConfig.MWB_setScanningRect(BarcodeConfig.MWB_CODE_MASK_QR,     RECT_LANDSCAPE_2D);
            // BarcodeConfig.MWB_setScanningRect(BarcodeConfig.MWB_CODE_MASK_RSS,    RECT_LANDSCAPE_1D);
            // BarcodeConfig.MWB_setScanningRect(BarcodeConfig.MWB_CODE_MASK_CODABAR,RECT_LANDSCAPE_1D);


            // set decoder effort level (1 - 5)
            // for live scanning scenarios, a setting between 1 to 3 will suffice
            // levels 4 and 5 are typically reserved for batch scanning
            BarcodeConfig.MWB_setLevel(2);

            //get and print Library version
            int    ver        = BarcodeConfig.MWB_getLibVersion();
            int    v1         = (ver >> 16);
            int    v2         = (ver >> 8) & 0xff;
            int    v3         = (ver & 0xff);
            String libVersion = v1.ToString() + "." + v2.ToString() + "." + v3.ToString();

            Console.WriteLine("Lib version: " + libVersion);
        }
Exemplo n.º 10
0
        public IEnumerable <DecodeStatistics> ProcessAllFiles()
        {
            if (string.IsNullOrWhiteSpace(_config.InputDirectory) ||
                !Directory.Exists(_config.InputDirectory))
            {
                throw new Exception("Invalid input directory");
            }

            var startTime = DateTime.Now.Ticks;
            var fileList  = Directory.GetFiles(_config.InputDirectory)
                            .Where(file => _config.AcceptedFileExtensions.Any(ext => file.ToLower().EndsWith(ext)))
                            .ToList();

            // start processing
            var currentState = 0;
            var errors       = new List <string> {
                "One or more exceptions occured. "
            };
            var errorsTemp    = new List <string>();
            var generalConfig = new BarcodeConfig()
            {
                PossibleFormats         = _config.PossibleFormats,
                TryMultipleBarcodeTypes = _config.TryMultipleBarcodeTypes,
            };

            var allResults  = new List <DecodeStatistics>();
            var _accessLock = new ReaderWriterLockSlim();

            while (true)
            {
                var files = fileList.Skip(currentState).Take(_config.NumberOfThreads);
                if (!files.Any())
                {
                    break;
                }

                var tasks = new List <Task>();
                foreach (var file in files)
                {
                    var taskHere = Task.Run(() =>
                    {
                        try
                        {
                            var barcodeConfig      = generalConfig.Clone() as BarcodeConfig;
                            barcodeConfig.FilePath = file;
                            var options            = Options.Create(barcodeConfig);

                            var decoder = new BarcodeDecoder(options, _bitmapReader);
                            decoder.StartDecoding();
                            var result = decoder.GetDecodeResult();

                            _accessLock.EnterWriteLock();
                            allResults.Add(result);
                            _accessLock.ExitWriteLock();
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("Error on file '" + file + "': " + ex.Message);
                        }
                    });
                    tasks.Add(taskHere);
                }

                try
                {
                    Task.WaitAll(tasks.ToArray());
                }
                catch (AggregateException ae)
                {
                    if (ae.InnerExceptions != null)
                    {
                        errorsTemp.AddRange(ae.InnerExceptions.Select(x => x.Message));
                    }
                }
                finally
                {
                    currentState += files.Count();
                }
            }

            if (errorsTemp.Count > 0)
            {
                errors.AddRange(errorsTemp);
            }
            _accessLock.Dispose();
            return(allResults);
        }
        public static void BuildAndRenderImageCompressedToOnePixelWideImageAsync(VideoCollection videoCollection, BarcodeConfig file, SettingsWrapper settings, IProgress <ProgressWrapper> progress, CancellationToken cancellationToken)
        {
            SetTempDir(settings);

            const int partDivider = 1000;

            Directory.CreateDirectory(videoCollection.Config.OnePixelImageDirectory);

            if (File.Exists(file.Barcode_1px.FullOutputFile))
            {
                _logger = LogManager.GetCurrentClassLogger();
                _logger.Warn($"Image {file.Barcode_1px.FullOutputFile} already exists, skipping image creation");

                return;
            }

            // get any image files now to save querying the file system for every image
            string[] imageFiles = Directory.GetFiles(videoCollection.Config.OnePixelImageDirectory);

            List <string> imageParts = new List <string>();

            using MagickImageCollection images = new MagickImageCollection();
            int geo = 0;

            for (var i = 0; i < videoCollection.Data.Images.Count; i++)
            {
                var frame = videoCollection.Data.Images[i];

                cancellationToken.ThrowIfCancellationRequested();

                // Resize the image to the output height, if required
                // Add page to define the image's location in the mosaic
                // Clone the image add add to the mosaic input list
                void ResizeAndClone(MagickImage image)
                {
                    if (image.Height != file.OutputHeight)
                    {
                        image.Resize(new MagickGeometry(1, file.OutputHeight)
                        {
                            IgnoreAspectRatio = true
                        });
                    }

                    image.Page = new MagickGeometry(geo, 0, 0, 0);

                    images.Add(image.Clone());
                }

                if (imageFiles.All(f => f != frame.Name))
                {
                    using MagickImage image = new MagickImage(Path.Combine(videoCollection.Config.ImageDirectory, frame.Name));
                    // Resize the image to a fixed size without maintaining the aspect ratio (normally an image will be resized to fit inside the specified size)
                    // These frames will be created to the same height as the original image
                    image.Resize(new MagickGeometry(1, image.Height)
                    {
                        IgnoreAspectRatio = true
                    });

                    image.Write(Path.Combine(videoCollection.Config.OnePixelImageDirectory, frame.Name));

                    ResizeAndClone(image);
                }
                else // get the image from the file system
                {
                    using MagickImage image = new MagickImage(Path.Combine(videoCollection.Config.OnePixelImageDirectory, frame.Name));
                    ResizeAndClone(image);
                }

                geo++;

                // split out and write partitioned images every 1000 frames to prevent ImageMagick's 'too many open files' fuckery
                if (i % partDivider == 0 && i != 0)
                {
                    var part = Path.Combine(settings.CoreSettings.MagickImageTempDir, $"{Guid.NewGuid()}.jpg");

                    using (IMagickImage result = images.Mosaic())
                    {
                        result.Write(part);
                    }

                    images.Clear();

                    imageParts.Add(part);

                    geo = 0;
                }

                progress.Report(new ProgressWrapper(videoCollection.Data.Images.Count, frame.Frame, ProcessType.RenderImageCompressedToOnePixelWide));
            }

            // create the last, smaller than 1000 px part
            var lastPart = Path.Combine(settings.CoreSettings.MagickImageTempDir, $"{Guid.NewGuid()}.jpg");

            using (IMagickImage result = images.Mosaic())
            {
                result.Write(lastPart);
            }

            images.Clear();

            imageParts.Add(lastPart);

            // add all the parts to the image collection
            geo = 0;

            foreach (var imagePart in imageParts)
            {
                using (MagickImage image = new MagickImage(imagePart))
                {
                    image.Page = new MagickGeometry(geo, 0, 0, 0);

                    images.Add(image.Clone());
                }

                geo = geo + partDivider;

                File.Delete(imagePart);
            }

            // lets do some f*****g barcode magic
            using (IMagickImage result = images.Mosaic())
            {
                result.Write(file.Barcode_1px.FullOutputFile);
            }
        }
Exemplo n.º 12
0
        static void Main()
        {
#if DEBUG
            //#warning COMMENTED_CODE_HERE!!!
            //            SetTestServiceUrls();
            //          IsAdmin = true;

            IsDebug = true;
#else
            IsAdmin = false;
            IsDebug = false;
#endif
            ThreadPool.SetMaxThreads(50, 100);

            Thread.CurrentThread.CurrentCulture       =
                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-us");

            Application.ThreadException += new ThreadExceptionEventHandler(OnThreadException);
            DelegateBase.Error          += new ThreadExceptionEventHandler(OnThreadException);
            VoucherPrinter.Error        += new ThreadExceptionEventHandler(OnThreadException);
            PrinterQueue.Error          += new ThreadExceptionEventHandler(OnThreadException);
            DelegateHelper.Error        += new ThreadExceptionEventHandler(OnThreadException);
            Global.Error += new ThreadExceptionEventHandler(OnThreadException);

            StateSaver.Default.Path = Path.ChangeExtension(Application.ExecutablePath, "dat");
            StateSaver.Default.Load();

            PluginLoader.Error += new ThreadExceptionEventHandler(OnThreadException);
            string path = Path.GetDirectoryName(Application.ExecutablePath);

            loader.Process(path, PluginLoader.Operation.Start);
            StateSaver.Default.Set(Strings.ClearScanDirectory, ConfigurationManager.AppSettings["ClearScanDirectory"].Cast <bool>());

            BarcodeConfig.Init();

            Speeker.Enabled = ConfigurationManager.AppSettings["SPEAK"].Cast <bool>();

            StateSaver.Default.Set(Strings.VERSION, Assembly.GetEntryAssembly().GetName());

#if !DEBUG
            if (ConfigurationManager.AppSettings["USE_SCAN_SERVER"].Cast <bool>())
            {
                if (!File.Exists(ConfigurationManager.AppSettings["ScanServerPath"]))
                {
                    MessageBox.Show("Cannot find scan server.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    ConfigurationManager.AppSettings["ScanServerPath"].StartProcessSafe();
                }
            }
#endif
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            FormLogin frmLogin = new FormLogin();
            if (frmLogin.ShowDialog() == DialogResult.OK)
            {
                Application.Run(new MainForm());
            }

            StateSaver.Default.Save();
            DelegateHelper.Close();

            new Action(() =>
            {
                var downloadDir = MainForm.GetAppSubFolder(Strings.DOWNLOAD);
                downloadDir.Delete(true);
            }).RunSafe();

            Global.Instance.DisposeSf();
            loader.Process(path, PluginLoader.Operation.Stop);
        }
        public static void customDecoderInit()
        {
            Console.WriteLine("Decoder initialization");

            //register your copy of library with givern SDK key

            int registerResult = BarcodeConfig.MWB_registerSDK("key");

            switch (registerResult)
            {
            case BarcodeConfig.MWB_RTREG_OK:
                Console.WriteLine("Registration OK");
                break;

            case BarcodeConfig.MWB_RTREG_INVALID_KEY:
                Console.WriteLine("Registration Invalid Key");
                break;

            case BarcodeConfig.MWB_RTREG_INVALID_CHECKSUM:
                Console.WriteLine("Registration Invalid Checksum");
                break;

            case BarcodeConfig.MWB_RTREG_INVALID_APPLICATION:
                Console.WriteLine("Registration Invalid Application");
                break;

            case BarcodeConfig.MWB_RTREG_INVALID_SDK_VERSION:
                Console.WriteLine("Registration Invalid SDK Version");
                break;

            case BarcodeConfig.MWB_RTREG_INVALID_KEY_VERSION:
                Console.WriteLine("Registration Invalid Key Version");
                break;

            case BarcodeConfig.MWB_RTREG_INVALID_PLATFORM:
                Console.WriteLine("Registration Invalid Platform");
                break;

            case BarcodeConfig.MWB_RTREG_KEY_EXPIRED:
                Console.WriteLine("Registration Key Expired");
                break;

            default:
                break;
            }

            // choose code type or types you want to search for

            // Our sample app is configured by default to search all supported barcodes...
            BarcodeConfig.MWB_setActiveCodes(BarcodeConfig.MWB_CODE_MASK_25 |
                                             BarcodeConfig.MWB_CODE_MASK_39 |
                                             BarcodeConfig.MWB_CODE_MASK_93 |
                                             BarcodeConfig.MWB_CODE_MASK_128 |
                                             BarcodeConfig.MWB_CODE_MASK_AZTEC |
                                             BarcodeConfig.MWB_CODE_MASK_DM |
                                             BarcodeConfig.MWB_CODE_MASK_EANUPC |
                                             BarcodeConfig.MWB_CODE_MASK_PDF |
                                             BarcodeConfig.MWB_CODE_MASK_QR |
                                             BarcodeConfig.MWB_CODE_MASK_CODABAR |
                                             BarcodeConfig.MWB_CODE_MASK_RSS |
                                             BarcodeConfig.MWB_CODE_MASK_MAXICODE |
                                             BarcodeConfig.MWB_CODE_MASK_DOTCODE |
                                             BarcodeConfig.MWB_CODE_MASK_11 |
                                             BarcodeConfig.MWB_CODE_MASK_MSI |
                                             BarcodeConfig.MWB_CODE_MASK_POSTAL);

            // But for better performance, only activate the symbologies your application requires...
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_25 );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_39 );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_93 );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_128 );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_AZTEC );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_DM );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_EANUPC );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_PDF );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_QR );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_CODABAR );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_RSS );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_MAXICODE );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_DOTCODE );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_11 );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_MSI );
            // BarcodeConfig.MWB_setActiveCodes( BarcodeConfig.MWB_CODE_MASK_POSTAL );


            // Our sample app is configured by default to search both directions...
            BarcodeConfig.MWB_setDirection(BarcodeConfig.MWB_SCANDIRECTION_HORIZONTAL | BarcodeConfig.MWB_SCANDIRECTION_VERTICAL);
            // set the scanning rectangle based on scan direction(format in pct: x, y, width, height)
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_25, RECT_FULL_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_39, RECT_FULL_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_93, RECT_FULL_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_128, RECT_FULL_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_AZTEC, RECT_FULL_2D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_DM, RECT_FULL_2D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_EANUPC, RECT_FULL_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_PDF, RECT_FULL_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_QR, RECT_FULL_2D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_RSS, RECT_FULL_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_CODABAR, RECT_FULL_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_DOTCODE, RECT_DOTCODE);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_11, RECT_FULL_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_MSI, RECT_FULL_1D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_MAXICODE, RECT_FULL_2D);
            BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_POSTAL, RECT_FULL_1D);

            // But for better performance, set like this for PORTRAIT scanning...
            // BarcodeConfig.MWB_setDirection(BarcodeConfig.MWB_SCANDIRECTION_VERTICAL);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_25, RECT_FULL_1D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_39, RECT_FULL_1D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_93, RECT_FULL_1D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_128, RECT_FULL_1D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_AZTEC, RECT_FULL_2D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_DM, RECT_FULL_2D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_EANUPC, RECT_FULL_1D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_PDF, RECT_FULL_1D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_QR, RECT_FULL_2D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_RSS, RECT_FULL_1D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_CODABAR, RECT_FULL_1D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_DOTCODE, RECT_DOTCODE);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_11, RECT_FULL_1D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_MSI, RECT_FULL_1D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_MAXICODE, RECT_FULL_2D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_POSTAL, RECT_FULL_1D);


            // or like this for LANDSCAPE scanning - Preferred for dense or wide codes...
            // BarcodeConfig.MWB_setDirection(BarcodeConfig.MWB_SCANDIRECTION_HORIZONTAL);
            // set the scanning rectangle based on scan direction(format in pct: x, y, width, height)
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_25, RECT_FULL_1D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_39, RECT_FULL_1D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_93, RECT_FULL_1D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_128, RECT_FULL_1D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_AZTEC, RECT_FULL_2D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_DM, RECT_FULL_2D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_EANUPC, RECT_FULL_1D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_PDF, RECT_FULL_1D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_QR, RECT_FULL_2D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_RSS, RECT_FULL_1D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_CODABAR, RECT_FULL_1D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_DOTCODE, RECT_DOTCODE);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_11, RECT_FULL_1D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_MSI, RECT_FULL_1D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_MAXICODE, RECT_FULL_2D);
            //BarcodeConfig.MWBsetScanningRect(BarcodeConfig.MWB_CODE_MASK_POSTAL, RECT_FULL_1D);


            BarcodeConfig.MWB_setMinLength(BarcodeConfig.MWB_CODE_MASK_25, 5);
            BarcodeConfig.MWB_setMinLength(BarcodeConfig.MWB_CODE_MASK_MSI, 5);
            BarcodeConfig.MWB_setMinLength(BarcodeConfig.MWB_CODE_MASK_39, 5);
            BarcodeConfig.MWB_setMinLength(BarcodeConfig.MWB_CODE_MASK_CODABAR, 5);
            BarcodeConfig.MWB_setMinLength(BarcodeConfig.MWB_CODE_MASK_11, 5);

            MWScannerViewController.setActiveParserMask(BarcodeConfig.MWP_PARSER_MASK_NONE);

            // set decoder effort level (1 - 5)
            // for live scanning scenarios, a setting between 1 to 3 will suffice
            // levels 4 and 5 are typically reserved for batch scanning
            BarcodeConfig.MWB_setLevel(2);


            //BarcodeConfig.MWBsetMaxThreads (1);   // disable multithreading
            //BarcodeConfig.MWBenableZoom(false);   // disable zoom
            //BarcodeConfig.MWBsetZoomLevels(150,300,0); // first 2 params to set zoom levels in %; third param to set initial level [0|1|2]
            //BarcodeConfig.MWB_setDuplicatesTimeout (2); //ignore scanning the same barcode; int timeout param is in seconds

            //get and print Library version
            int    ver        = BarcodeConfig.MWB_getLibVersion();
            int    v1         = (ver >> 16);
            int    v2         = (ver >> 8) & 0xff;
            int    v3         = (ver & 0xff);
            String libVersion = v1.ToString() + "." + v2.ToString() + "." + v3.ToString();

            Console.WriteLine("Lib version: " + libVersion);
        }