public WriteBarcodeInteractiveMode(BarcodeEngine engine, byte[] data, PDF417BarcodeWriteOptions writeOptions) : base()
 {
     _data                = data;
     _engine              = engine;
     _writeOptions        = writeOptions;
     _bigEnoughForBarcode = false;
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            String fileToConvert = @"FILE PATH HERE";

            RasterSupport.SetLicense(@"C:\LEADTOOLS 20\Common\License\LEADTOOLS.LIC", System.IO.File.ReadAllText(@"C:\LEADTOOLS 20\Common\License\LEADTOOLS.LIC.KEY"));

            using (RasterCodecs codecs = new RasterCodecs())
            {
                using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, false))
                {
                    ocrEngine.Startup(null, null, null, @"C:\LEADTOOLS 20\Bin\Common\OcrLEADRuntime");

                    using (IOcrPage ocrPage = ocrEngine.CreatePage(ocrEngine.RasterCodecsInstance.Load(fileToConvert, 1), OcrImageSharingMode.AutoDispose))
                    {
                        ocrPage.AutoZone(null);
                        ocrPage.Recognize(null);
                        string recognizedCharacters = ocrPage.GetText(-1);

                        BarcodeEngine engine     = new BarcodeEngine();
                        int           resolution = 300;
                        using (RasterImage image = RasterImage.Create((int)(8.5 * resolution), (int)(11.0 * resolution), 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White)))
                        {
                            BarcodeWriter writer = engine.Writer;

                            QRBarcodeData data = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR) as QRBarcodeData;

                            data.Bounds = new LeadRect(0, 0, image.ImageWidth, image.ImageHeight);
                            QRBarcodeWriteOptions writeOptions = writer.GetDefaultOptions(data.Symbology) as QRBarcodeWriteOptions;
                            writeOptions.XModule             = 30;
                            writeOptions.HorizontalAlignment = BarcodeAlignment.Near;
                            writeOptions.VerticalAlignment   = BarcodeAlignment.Near;
                            data.Value = recognizedCharacters;

                            writer.CalculateBarcodeDataBounds(new LeadRect(0, 0, image.ImageWidth, image.ImageHeight), image.XResolution, image.YResolution, data, writeOptions);
                            Console.WriteLine("{0} by {1} pixels", data.Bounds.Width, data.Bounds.Height);

                            writer.WriteBarcode(image, data, writeOptions);

                            CropCommand cmd = new CropCommand(new LeadRect(0, 0, data.Bounds.Width, data.Bounds.Height));
                            cmd.Run(image);

                            codecs.Save(image, "QR.tif", RasterImageFormat.CcittGroup4, 1);

                            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                            {
                                var process = new Process();
                                process.StartInfo = new ProcessStartInfo("QR.tif")
                                {
                                    UseShellExecute = true
                                };
                                process.Start();
                            }

                            Console.WriteLine();
                        }
                    }
                }
            }
        }
        public BarcodesController()
        {
            barcodeEngineInstance = new BarcodeEngine();
            // Requires a license file that unlocks 1D barcode read functionality.
            string MY_LICENSE_FILE  = @"C:\LEADTOOLS 20\Common\License\leadtools.lic";
            string MY_DEVELOPER_KEY = System.IO.File.ReadAllText(@"C:\LEADTOOLS 20\Common\License\leadtools.lic.key");

            RasterSupport.SetLicense(MY_LICENSE_FILE, MY_DEVELOPER_KEY);
        }
Beispiel #4
0
        //public static byte[] CreateBarcode( string value, int resolution, int Width, int Height, bool Save2File,bool usingMemory, ref string ErrMsg)
        //{
        //    byte[] arrImg;
        //    BarcodeEngine barEngine;
        //    try
        //    {
        //        RasterImage theImage = RasterImage.Create((int)(8.5 * resolution), (int)(11.0 * resolution), 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White));
        //        // Unlock barcode support.
        //        // Note that this is a sample key, which will not work in your toolkit
        //        BarcodeEngine.Startup(BarcodeMajorTypeFlags.Barcodes1d);
        //        BarcodeEngine.Startup(BarcodeMajorTypeFlags.BarcodesPdfWrite);
        //        BarcodeEngine.Startup(BarcodeMajorTypeFlags.BarcodesDatamatrixWrite);
        //        BarcodeEngine.Startup(BarcodeMajorTypeFlags.BarcodesQrWrite);

        //        // Initialize barcodes
        //        barEngine = new BarcodeEngine();

        //        BarcodeData data = new BarcodeData();

        //        LeadRect rc = new LeadRect(0, 0, Width, Height);
        //        data.Unit = BarcodeUnit.ScanlinesPerPixels;
        //        data.Location = rc;
        //        data.SearchType = BarcodeSearchTypeFlags.DatamatrixDefault;

        //        string[] barcodeText;
        //        barcodeText = new string[1];
        //        barcodeText[0] = value;
        //        data.Data = BarcodeData.ConvertFromStringArray(barcodeText);

        //        BarcodeColor barColor = new BarcodeColor();
        //        barColor.BarColor = RasterColor.FromKnownColor(RasterKnownColor.Black);
        //        barColor.SpaceColor = RasterColor.FromKnownColor(RasterKnownColor.White);
        //        Barcode1d bar1d = new Barcode1d();
        //        BarcodeWritePdf barPDF = new BarcodeWritePdf();
        //        BarcodeWriteDatamatrix barDM = new BarcodeWriteDatamatrix();
        //        bar1d.StandardFlags = Barcode1dStandardFlags.Barcode1dCode128EncodeA;

        //        barDM.Justify = BarcodeJustifyFlags.Right;
        //        barDM.FileIdHigh = 0;
        //        barDM.FileIdLow = 0;
        //        barDM.GroupNumber = 0;
        //        barDM.GroupTotal = 0;
        //        barDM.XModule = 0;

        //        BarcodeWriteQr barQR = new BarcodeWriteQr();
        //        string barcodeFileName = AppDomain.CurrentDomain.BaseDirectory + @"\barcode.tif";
        //        barEngine.Write(theImage, data, barColor, BarcodeWriteFlags.UseColors | BarcodeWriteFlags.Transparent | BarcodeWriteFlags.DisableCompression, bar1d, barPDF, barDM, barQR, LeadRect.Empty);
        //        if (usingMemory)
        //        {
        //            using (MemoryStream _stream = new MemoryStream())
        //            {
        //                using (RasterCodecs _Codecs = new RasterCodecs())
        //                {
        //                    _Codecs.Save(theImage, _stream, RasterImageFormat.Tif, theImage.BitsPerPixel);
        //                    arrImg = _stream.ToArray();
        //                    if (Save2File)
        //                    {
        //                        _Codecs.Save(theImage, barcodeFileName, RasterImageFormat.Tif, theImage.BitsPerPixel);
        //                    }
        //                }
        //            }
        //        }
        //        else
        //        {
        //            using (RasterCodecs _Codecs = new RasterCodecs())
        //            {
        //                _Codecs.Save(theImage, barcodeFileName, RasterImageFormat.Tif, theImage.BitsPerPixel);
        //                arrImg = System.IO.File.ReadAllBytes(barcodeFileName);
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        ErrMsg = ex.Message;
        //        return null;
        //    }
        //    return arrImg;

        //}
        public static byte[] CreateBarcode(BarcodeSymbology _BarcodeSymbology, string value, int resolution, int Width, int Height, bool Save2File, bool usingMemory, ref string ErrMsg)
        {
            ErrMsg = "";
            BarcodeEngine barcodeEngineInstance = new BarcodeEngine();
            RasterImage   theImage = RasterImage.Create((int)(8.5 * resolution), (int)(11.0 * resolution), 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White));
            // Create a UPC A barcode
            BarcodeData data = new BarcodeData();

            data.Symbology = _BarcodeSymbology;
            data.Value     = value;
            data.Bounds    = new LogicalRectangle(10, 10, Width, Height, LogicalUnit.Pixel);
            // Setup the options to enable error checking and show the text on the bottom of the barcode
            OneDBarcodeWriteOptions options = new OneDBarcodeWriteOptions();

            options.EnableErrorCheck = true;
            options.TextPosition     = BarcodeOutputTextPosition.None;// OneDBarcodeTextPosition.Default;
            byte[] arrImg;
            try
            {
                string barcodeFileName = AppDomain.CurrentDomain.BaseDirectory + @"\barcode.tif";
                // Write the barcode
                barcodeEngineInstance.Writer.WriteBarcode(theImage, data, options);
                if (usingMemory)
                {
                    using (MemoryStream _stream = new MemoryStream())
                    {
                        using (RasterCodecs _Codecs = new RasterCodecs())
                        {
                            _Codecs.Save(theImage, _stream, RasterImageFormat.Tif, theImage.BitsPerPixel);

                            arrImg = _stream.ToArray();
                            if (Save2File)
                            {
                                _Codecs.Save(theImage, barcodeFileName, RasterImageFormat.Tif, theImage.BitsPerPixel);
                            }
                        }
                    }
                }
                else
                {
                    using (RasterCodecs _Codecs = new RasterCodecs())
                    {
                        _Codecs.Save(theImage, barcodeFileName, RasterImageFormat.Tif, theImage.BitsPerPixel);
                        arrImg = System.IO.File.ReadAllBytes(barcodeFileName);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
                ErrMsg = ex.Message;
                return(null);
            }

            return(arrImg);
        }
 private IEnumerable<string> GetText(LogicalRectangle leadRect, BarcodeReadOptions[] coreReadOptions, ImageSource image, BarcodeImageType imageType)
 {
     var engine = new BarcodeEngine();
     engine.Reader.ImageType = imageType;
     var barcodeDatas = engine.Reader.ReadBarcodes(image.ToRasterImage(), leadRect, 10, BarcodeSymbologies.ToArray(), coreReadOptions);
     var textForStrategy = barcodeDatas
         .Select(data => data.Value)
         .DefaultIfEmpty();
     return textForStrategy;
 }
Beispiel #6
0
        public SingleUseCouponsController(ApplicationDbContext context, IHostingEnvironment host)
        {
            _context = context;
            _host    = host;
            barcodeEngineInstance = new BarcodeEngine();
            // Requires a license file that unlocks 1D barcode read functionality.
            string MY_LICENSE_FILE  = @"C:\LEADTOOLS 20\Common\License\leadtools.lic";
            string MY_DEVELOPER_KEY = System.IO.File.ReadAllText(@"C:\LEADTOOLS 20\Common\License\leadtools.lic.key");

            RasterSupport.SetLicense(MY_LICENSE_FILE, MY_DEVELOPER_KEY);
        }
Beispiel #7
0
        public ReadBarcodesDialogBox(BarcodeEngine barcodeEngine, BarcodeSymbology[] symbologies, RasterImage image, bool currentPageOnly, LeadRect bounds)
        {
            InitializeComponent();

            _barcodeEngine           = barcodeEngine;
            _symbologies             = symbologies;
            _userSelectedSymbologies = symbologies;
            _rasterImage             = image;
            _currentPageOnly         = currentPageOnly;
            _bounds = bounds;
            _showReadBarcodeOptions = false;
        }
Beispiel #8
0
        private IEnumerable <string> GetText(LogicalRectangle leadRect, BarcodeReadOptions[] coreReadOptions, IImage image, BarcodeImageType imageType)
        {
            var engine = new BarcodeEngine();

            engine.Reader.ImageType = imageType;
            var barcodeDatas    = engine.Reader.ReadBarcodes(image.FromImageToRasterImage(), leadRect, 10, BarcodeSymbologies.ToArray(), coreReadOptions);
            var textForStrategy = barcodeDatas
                                  .Select(data => data.Value)
                                  .DefaultIfEmpty();

            return(textForStrategy);
        }
Beispiel #9
0
        public ReadBarcodeOptionsDialogBox(BarcodeEngine barcodeEngine, RasterImage sampleSymbologiesRasterImage, BarcodeOptions barcodeOptions)
        {
            InitializeComponent();

            _availableSymbologyListBox.SampleSymbologiesRasterImage = sampleSymbologiesRasterImage;
            _toReadSymbologyListBox.SampleSymbologiesRasterImage    = sampleSymbologiesRasterImage;

            _barcodeEngine = barcodeEngine;

            _selectedGroupIndex  = barcodeOptions.ReadOptionsGroupIndex;
            _selectedSymbologies = barcodeOptions.ReadOptionsSymbologies;
            _imageResolution     = barcodeOptions.ImageResolution;
        }
Beispiel #10
0
        private void WriteBarcodeForm_Load(object sender, System.EventArgs e)
        {
            // initialize the _viewer object
            _viewer           = new ImageViewer();
            _viewer.Dock      = DockStyle.Fill;
            _viewer.BackColor = Color.DarkGray;
            Controls.Add(_viewer);
            _viewer.BringToFront();

            // initialize the codecs object.
            _codecs = new RasterCodecs();

            try
            {
                string imagePath = Path.Combine(DemosGlobal.ImagesFolder, "license_sample_rear_blank.png");
                _viewer.Image = _codecs.Load(imagePath);
            }
            catch
            {
                _viewer.Image = RasterImage.Create(1100, 700, 24, 150, RasterColor.White);
            }

            _barcodeEngine = new BarcodeEngine();
            _writeOptions  = (PDF417BarcodeWriteOptions)_barcodeEngine.Writer.GetDefaultOptions(BarcodeSymbology.PDF417);

            //Refer to AAMVA CDS 2016 Section D.3 thru D.11.2

            //Must range from 0.0066 to 0.015 inches
            _writeOptions.XModule = 15; //0.015
            //Must >= 3
            _writeOptions.XModuleAspectRatio = 3;
            //Error level must be at least 3, 5 is recommended
            _writeOptions.ECCLevel = PDF417BarcodeECCLevel.Level5;
            //Default WidthAspectRatio is 2:1. 4:1 looks similar to ID barcodes in the wild
            _writeOptions.SymbolWidthAspectRatio = 4;
            //Default quiet zone for PDF417 is 2 * XModule


            _viewer.BeginUpdate();
            WriteBarcodeInteractiveMode writeBarcodeInteractiveMode = new WriteBarcodeInteractiveMode(_barcodeEngine, _aamvaData, _writeOptions);

            writeBarcodeInteractiveMode.IsEnabled = true;
            ImageViewerPanZoomInteractiveMode panZoomInteractiveMode = new ImageViewerPanZoomInteractiveMode();

            _viewer.InteractiveModes.Add(writeBarcodeInteractiveMode);
            _viewer.InteractiveModes.Add(panZoomInteractiveMode);
            _viewer.EndUpdate();


            UpdateMyControls();
        }
Beispiel #11
0
        /// <summary>
        /// Called by MainForm and internally whenever the document barcodes are updated
        /// </summary>
        public void Populate()
        {
            _barcodesListView.Items.Clear();

            if (_documentBarcodes != null && _rasterImage != null)
            {
                PageBarcodes pageBarcodes = _documentBarcodes.Pages[_rasterImage.Page - 1];
                foreach (BarcodeData data in pageBarcodes.Barcodes)
                {
                    ListViewItem item = new ListViewItem();

                    item.Text = BarcodeEngine.GetSymbologyFriendlyName(data.Symbology);
                    LeadRect rc = data.Bounds;
                    item.SubItems.Add(string.Format("{0}, {1}, {2}, {3}", rc.Left, rc.Top, rc.Right, rc.Bottom));

                    string value = data.Value;
                    if (!string.IsNullOrEmpty(value))
                    {
                        // Parse the QR barcodes for ECI data
                        string eciData = null;
                        if (data.Symbology == BarcodeSymbology.QR || data.Symbology == BarcodeSymbology.MicroQR)
                        {
                            eciData = BarcodeData.ParseECIData(data.GetData());
                        }

                        if (!string.IsNullOrEmpty(eciData))
                        {
                            item.SubItems.Add(eciData);
                        }
                        else
                        {
                            item.SubItems.Add(value);
                        }
                    }
                    else
                    {
                        item.SubItems.Add("<NO DATA>");
                    }

                    _barcodesListView.Items.Add(item);
                }

                if (pageBarcodes.SelectedIndex != -1)
                {
                    _barcodesListView.Items[pageBarcodes.SelectedIndex].Selected = true;
                    _barcodesListView.EnsureVisible(pageBarcodes.SelectedIndex);
                }
            }

            UpdateUIState();
        }
Beispiel #12
0
        private bool Init()
        {
            // Check support required to use this program
            if (RasterSupport.IsLocked(RasterSupportType.Barcodes1D) && RasterSupport.IsLocked(RasterSupportType.Barcodes2D))
            {
                Messager.ShowError(this, BarcodeGlobalization.GetResxString(GetType(), "Resx_LEADBarcodeSupport"));
                return(false);
            }

            try
            {
                _rasterCodecs = new RasterCodecs();
            }
            catch (Exception ex)
            {
                Messager.ShowError(this, string.Format("RasterCodec initialize error: {0}", ex.Message));
                return(false);
            }

            // this is very important, must be placed leadtools.engine.dll in this path
            _rasterCodecs.Options.Pdf.InitialPath = AppDomain.CurrentDomain.BaseDirectory;

            _barcodeOptions = BarcodeOptions.Load();

            //BarcodeSymbology[] supportedSymbologies = BarcodeEngine.GetSupportedSymbologies();
            WriteLine(string.Format("{0} Supported symbologies:", _barcodeOptions.ReadOptionsSymbologies.Length), TraceEventType.Information);
            foreach (BarcodeSymbology symbology in _barcodeOptions.ReadOptionsSymbologies)
            {
                WriteLine(string.Format("{0}: {1}", symbology, BarcodeEngine.GetSymbologyFriendlyName(symbology)), TraceEventType.Information);
            }
            WriteLine(string.Format("----------"), TraceEventType.Information);

            _sampleSymbologiesRasterImage = null;

            // Create the barcodes symbologies multi-frame RasterImage
            using (Stream stream = GetType().Assembly.GetManifestResourceStream("BarcodeSplitManage.Resources.Symbologies.tif"))
            {
                _rasterCodecs.Options.Load.AllPages = true;
                _sampleSymbologiesRasterImage       = _rasterCodecs.Load(stream);
            }

            _barcodeEngine = new BarcodeEngine();
            _barcodeEngine.Reader.ImageType = BarcodeImageType.Unknown;
            _barcodeEngine.Reader.EnableReturnFourPoints = false;
            // Continue on errors
            _barcodeEngine.Reader.ErrorMode = BarcodeReaderErrorMode.IgnoreAll;

            _directorySettings = new DirectorySettings();

            return(true);
        }
        public WriteBarcodeDialogBox(BarcodeEngine barcodeEngine, RasterImage sampleSymbologiesRasterImage, LeadRect bounds, int groupIndex, BarcodeSymbology symbology, WriteBarcodeDelegate writeBarcodeDelegate)
        {
            InitializeComponent();

            _availableSymbologyListBox.SampleSymbologiesRasterImage = sampleSymbologiesRasterImage;

            _barcodeEngine = barcodeEngine;
            _bounds        = bounds;

            _selectedGroupIndex = groupIndex;
            _selectedSymbology  = symbology;

            _writeBarcodeDelegate = writeBarcodeDelegate;
        }
        public ReadBarcodeOptionsDialogBox(BarcodeEngine barcodeEngine, RasterImage sampleSymbologiesRasterImage, int selectedGroupIndex, BarcodeSymbology[] selectedSymbologies, bool readBarcodesWhenDialogCloses)
        {
            InitializeComponent();

            _availableSymbologyListBox.SampleSymbologiesRasterImage = sampleSymbologiesRasterImage;
            _toReadSymbologyListBox.SampleSymbologiesRasterImage    = sampleSymbologiesRasterImage;

            _barcodeEngine = barcodeEngine;

            _selectedGroupIndex  = selectedGroupIndex;
            _selectedSymbologies = selectedSymbologies;

            _readBarcodesWhenDialogClosesCheckBox.Checked = readBarcodesWhenDialogCloses;
        }
Beispiel #15
0
        private void DrawBarcodeData(Graphics g, RasterImage image, BarcodeData data, StringFormat sf, Brush brush, Pen pen)
        {
            LeadRect  rect = data.Bounds;
            LeadRectD rc   = new LeadRectD(rect.X, rect.Y, rect.Width, rect.Height);
            string    line = BarcodeEngine.GetSymbologyFriendlyName(data.Symbology);

            if (FourPoints && data.Symbology != BarcodeSymbology.Aztec && data.Symbology != BarcodeSymbology.Maxi && data.Symbology != BarcodeSymbology.MicroQR)
            {
                LeadPointD[] pointsL = new LeadPointD[4];                Point[] points = new Point[4];
                pointsL[0].X = ((int)rc.Left & 0xffff);                  pointsL[0].Y = ((int)rc.Left >> 16);
                pointsL[1].X = ((int)rc.Top & 0xffff);                   pointsL[1].Y = ((int)rc.Top >> 16);
                pointsL[2].X = ((int)rc.Width & 0xffff);                 pointsL[2].Y = ((int)rc.Width >> 16);
                pointsL[3].X = ((int)rc.Height & 0xffff);                pointsL[3].Y = ((int)rc.Height >> 16);

                _rasterImageViewer.ImageTransform.TransformPoints(pointsL);

                for (int i = 0; i < 4; i++)
                {
                    points[i].X = (int)pointsL[i].X;    points[i].Y = (int)pointsL[i].Y;
                }

                g.DrawPolygon(pen, points);

                SizeF size = g.MeasureString(line, Font, points[2].X - points[0].X, sf);
                rc.Width  = (int)size.Width + 1;
                rc.Height = (int)size.Height + 1;

                g.FillRectangle(brush, points[0].X, points[0].Y, (int)rc.Width, (int)rc.Height);
                g.DrawString(line, Font, Brushes.White, new RectangleF(points[0].X, points[0].Y, (int)rc.Width, (int)rc.Height), sf);
            }
            else
            {
                rc = _rasterImageViewer.ImageTransform.TransformRect(rc);
                rc.Inflate(3, 3);

                if (rc.Width < 10 || rc.Height < 10)
                {
                    return;
                }

                g.DrawRectangle(pen, (int)rc.X, (int)rc.Y, (int)rc.Width, (int)rc.Height);

                SizeF size = g.MeasureString(line, Font, (int)rc.Width, sf);
                rc.Width  = (int)size.Width + 1;
                rc.Height = (int)size.Height + 1;

                g.FillRectangle(brush, (int)rc.X, (int)rc.Y, (int)rc.Width, (int)rc.Height);
                g.DrawString(line, Font, Brushes.White, new RectangleF((int)rc.X, (int)rc.Y, (int)rc.Width, (int)rc.Height), sf);
            }
        }
        protected override void OnStart(string[] args)
        {
            _barcodeOptions = BarcodeOptions.Load();

            //BarcodeSymbology[] supportedSymbologies = BarcodeEngine.GetSupportedSymbologies();
            Console.WriteLine(string.Format("{0} Supported symbologies:", _barcodeOptions.ReadOptionsSymbologies.Length));
            foreach (BarcodeSymbology symbology in _barcodeOptions.ReadOptionsSymbologies)
            {
                Console.WriteLine(string.Format("{0}: {1}", symbology, BarcodeEngine.GetSymbologyFriendlyName(symbology)));
            }

            _directorySettings.Load();
            DoPDFSplitStart();

            ServiceLog.WriteLog("Service started");
        }
        protected override void OnLoad(EventArgs e)
        {
            // Requires a license file that unlocks 1D barcode read functionality.
            string MY_LICENSE_FILE  = @"C:\LEADTOOLS 20\Common\License\leadtools.lic";
            string MY_DEVELOPER_KEY = System.IO.File.ReadAllText(@"C:\LEADTOOLS 20\Common\License\leadtools.lic.key");

            RasterSupport.SetLicense(MY_LICENSE_FILE, MY_DEVELOPER_KEY);

            // Create the BarcodeEngine instance
            barcodeEngineInstance = new BarcodeEngine();

            readBarcodesButton.Click += readBarcodesButton_Click;
            loadImageButton.Click    += loadImageButton_Click;

            base.OnLoad(e);
        }
        private BarcodeData[] ReadBarcode(RasterImage image)
        {
            BarcodeEngine _barcodeEngine = new BarcodeEngine();

            _barcodeEngine.Reader.ImageType = BarcodeImageType.Unknown;
            _barcodeEngine.Reader.EnableReturnFourPoints = false;
            // Continue on errors
            _barcodeEngine.Reader.ErrorMode = BarcodeReaderErrorMode.IgnoreAll;

            BarcodeData[] barcodes = new BarcodeData[] { };

            try
            {
                barcodes = _barcodeEngine.Reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, _barcodeOptions.ReadOptionsSymbologies, null);
            }
            catch (Exception ex)
            {
                SendMsgEvent(this, new PDFSplitterEventArgs(_directoryData.ID, 2, string.Format("Detect barcodes error: {0}", ex.Message), TraceEventType.Error));
            }

            return(barcodes);
        }
        protected override void Run()
        {
            Progress(33, "Creating components");
            BarcodeEngine engine = new BarcodeEngine();

            BarcodeReadOptions[] options = GetHorizontalAndVerticalReadBarcodeOptions(engine.Reader);

            Progress(66, "Detecting barcode symbology");
            BarcodeData[] bc = engine.Reader.ReadBarcodes(image, rect, 1, engine.Reader.GetAvailableSymbologies(), options);

            if (bc != null && bc.Length > 0)
            {
                DetectedSymbology   = bc[0].Symbology;
                IsSymbologyDetected = true;
            }
            else
            {
                IsSymbologyDetected = false;
            }

            base.Run();
        }
Beispiel #20
0
        public BarcodeFieldDialog(BarcodeField ff, RasterImage image) : this()
        {
            bcff       = ff;
            this.image = image;
            BarcodeEngine eng = new BarcodeEngine();

            BarcodeSymbology[] symbologies = (BarcodeSymbology[])Enum.GetValues(typeof(BarcodeSymbology));

            cboxSymbology.DisplayMember = "FriendlyName";
            cboxSymbology.ValueMember   = "ActualSymbology";

            for (int i = 0; i < symbologies.Length; i++)
            {
                string symbology = "Unknown";
                try
                {
                    symbology = BarcodeEngine.GetSymbologyFriendlyName(symbologies[i]);
                }
                catch (Exception)
                {
                    symbology = Enum.GetName(typeof(BarcodeSymbology), symbologies[i]);
                }

                BarcodeFriendlySymbology bfs = new BarcodeFriendlySymbology(symbologies[i], symbology);

                cboxSymbology.Items.Add(bfs);

                if (bfs.ActualSymbology == bcff.Symbology)
                {
                    cboxSymbology.SelectedItem = bfs;
                }
            }

            txtName.Text = bcff.Name;
            if (cboxSymbology.SelectedItem == null)
            {
                cboxSymbology.SelectedIndex = 0;
            }
        }
Beispiel #21
0
        // ReadBarcode function search the scanned image  for 1D Code128 barcode
        private string[] ReadBarcode(RasterImage TwainImage)
        {
            _codecs.ThrowExceptionsOnInvalidImages = true;
            BarcodeEngine barEngine;

            string[] strDataArray = null;
            try
            {
                barEngine = new BarcodeEngine();

                // Set the Barcode search rectangle
                LeadRect searchRect = LeadRect.Empty;

                // Read the barcodes using default options
                barEngine.Reader.ErrorMode = BarcodeReaderErrorMode.IgnoreAll;
                BarcodeData[] barcodes = barEngine.Reader.ReadBarcodes(TwainImage, searchRect, 0, new BarcodeSymbology[] { BarcodeSymbology.Code128 });

                if (barcodes.Length > 0)
                {
                    strDataArray = new string[barcodes.Length];
                    for (int nIndex = 0; nIndex < barcodes.Length; nIndex++)
                    {
                        strDataArray[nIndex] = barcodes[nIndex].Value;
                    }

                    return(strDataArray);
                }
                else
                {
                    return(null);
                }
            }
            catch (BarcodeException ex)
            {
                Messager.ShowError(this, ex.Message);
                return(null);
            }
        }
Beispiel #22
0
        private async Task <HttpResponseMessage> ExtractBarcodes([FromUri] BarcodeWebRequest request, int barcodeAmount)
        {
            try
            {
                AuthenticateRequest();

                if (!VerifyCommonParameters(request))
                {
                    throw new MalformedRequestException();
                }

                var symbologyList = new List <BarcodeSymbology>();
                if (string.IsNullOrEmpty(request.symbologies))//If no symbology string is passed, default to all symbologies.
                {
                    symbologyList = Enum.GetValues(typeof(BarcodeSymbology)).OfType <BarcodeSymbology>().ToList();
                    symbologyList.Remove(BarcodeSymbology.Unknown);
                }
                else
                {
                    symbologyList = ExtractBarcodeSymbologies(request.symbologies);
                    //If the user did supply a list of symbologies, but they could not be parsed, we will deny the request.
                    if (symbologyList.Count == 0)
                    {
                        throw new MalformedRequestException();
                    }
                }


                using (var stream = await GetImageStream(request.fileUrl))
                {
                    int lastPage = request.LastPage;
                    ValidateFile(stream, ref lastPage);
                    ConversionEngine    conversion = new ConversionEngine();
                    LoadDocumentOptions options    = new LoadDocumentOptions()
                    {
                        FirstPageNumber = request.FirstPage,
                        LastPageNumber  = lastPage
                    };
                    RecognitionEngine recognitionEngine = new RecognitionEngine();
                    BarcodeEngine     barcodeEngine     = new BarcodeEngine();

                    var barcodeList = recognitionEngine.ExtractBarcode(stream, options, barcodeEngine, symbologyList.ToArray(), barcodeAmount, false);
                    List <BarcodeResultData> results = new List <BarcodeResultData>();
                    foreach (var obj in barcodeList)
                    {
                        foreach (var d in obj.BarcodeData)
                        {
                            var result = new BarcodeResultData(obj.PageNumber, d.Symbology.ToString(), d.Value, new Rectangle(d.Bounds.X, d.Bounds.Y, d.Bounds.Width, d.Bounds.Height), d.RotationAngle);;
                            results.Add(result);
                        }
                    }


                    return(new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new StringContent(JsonConvert.SerializeObject(results))
                    });
                }
            }
            catch (Exception e)
            {
                return(GenerateExceptionMessage(e));
            }
        }
Beispiel #23
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (_sampleSymbologiesRasterImage == null)
            {
                return;
            }

            if (e.Index == -1)
            {
                return;
            }

            Rectangle rc = new Rectangle(e.Bounds.X + _delta, e.Bounds.Y + _delta, e.Bounds.Width - 10, e.Bounds.Height - _delta);

            if (_stringFormat == null)
            {
                _stringFormat               = new StringFormat();
                _stringFormat.Alignment     = StringAlignment.Center;
                _stringFormat.LineAlignment = StringAlignment.Far;
            }

            BarcodeSymbology symbology = (BarcodeSymbology)Items[e.Index];
            string           name      = BarcodeEngine.GetSymbologyFriendlyName(symbology);

            _sampleSymbologiesRasterImage.Page = (int)symbology;

            if (_itemPen == null)
            {
                _itemPen = new Pen(Brushes.Black, 2);
            }

            e.Graphics.DrawRectangle(_itemPen, rc);
            e.Graphics.FillRectangle(Brushes.White, rc);

            RasterPaintProperties paintProperties = RasterPaintProperties.Default;

            if (RasterSupport.IsLocked(RasterSupportType.Document))
            {
                paintProperties.PaintDisplayMode = RasterPaintDisplayModeFlags.Bicubic;
            }
            else
            {
                paintProperties.PaintDisplayMode = RasterPaintDisplayModeFlags.ScaleToGray;
            }

            LeadRect imageRect = new LeadRect(rc.X + 2, rc.Y + 2, rc.Width - 4, rc.Height * 2 / 3);

            imageRect = RasterImage.CalculatePaintModeRectangle(
                _sampleSymbologiesRasterImage.ImageWidth,
                _sampleSymbologiesRasterImage.ImageHeight,
                imageRect,
                RasterPaintSizeMode.FitAlways,
                RasterPaintAlignMode.CenterAlways,
                RasterPaintAlignMode.CenterAlways);

            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                e.Graphics.FillRectangle(SystemBrushes.Highlight, rc);
                RasterImagePainter.Paint(_sampleSymbologiesRasterImage, e.Graphics, imageRect, paintProperties);
                e.Graphics.DrawRectangle(Pens.Black, imageRect.X, imageRect.Y, imageRect.Width, imageRect.Height);
                e.Graphics.DrawString(name, Font, SystemBrushes.HighlightText, rc, _stringFormat);
            }
            else
            {
                e.Graphics.FillRectangle(SystemBrushes.Control, rc);
                RasterImagePainter.Paint(_sampleSymbologiesRasterImage, e.Graphics, imageRect, paintProperties);
                e.Graphics.DrawRectangle(Pens.Black, imageRect.X, imageRect.Y, imageRect.Width, imageRect.Height);
                e.Graphics.DrawString(name, Font, SystemBrushes.ControlText, rc, _stringFormat);
            }
        }
Beispiel #24
0
 private void StartupBarcode()
 {
     _barcodeEngine = new BarcodeEngine();
 }
        public ReadBarcodesResponse ReadBarcodes(ReadBarcodesRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            var pageNumber = request.PageNumber;

            if (string.IsNullOrEmpty(request.DocumentId))
            {
                throw new ArgumentException("documentId must not be null");
            }

            if (pageNumber < 0)
            {
                throw new ArgumentException("'pageNumber' must be a value greater than or equal to 0");
            }

            // Default is page 1
            if (pageNumber == 0)
            {
                pageNumber = 1;
            }

            try
            {
                // Now load the document
                var cache = ServiceHelper.Cache;
                using (var document = DocumentFactory.LoadFromCache(cache, request.DocumentId))
                {
                    DocumentHelper.CheckLoadFromCache(document);
                    DocumentHelper.CheckPageNumber(document, pageNumber);

                    // Set the options
                    var barcodeEngine = new BarcodeEngine();
                    document.Barcodes.BarcodeEngine = barcodeEngine;
                    var barcodeReader = barcodeEngine.Reader;

                    // Get the symbologies to read
                    var symbologies = new List <BarcodeSymbology>();
                    if (request.Symbologies != null && request.Symbologies.Length > 0)
                    {
                        symbologies.AddRange(request.Symbologies);
                    }
                    else
                    {
                        symbologies.AddRange(barcodeReader.GetAvailableSymbologies());
                    }

                    // Load the options from config
                    bool usedCustomOptions = ServiceHelper.SetBarcodeReadOptions(barcodeReader);
                    if (!usedCustomOptions)
                    {
                        ServiceHelper.InitBarcodeReader(barcodeReader, false);
                    }

                    var documentPage = document.Pages[pageNumber - 1];
                    var barcodes     = documentPage.ReadBarcodes(request.Bounds, request.MaximumBarcodes, symbologies.ToArray());
                    if (barcodes.Length == 0 && !usedCustomOptions)
                    {
                        // Did not find any barcodes, try again with double pass enabled
                        ServiceHelper.InitBarcodeReader(barcodeReader, true);

                        // Do not read MicroPDF417 in this pass since it is too slow
                        if (symbologies != null && symbologies.Contains(BarcodeSymbology.MicroPDF417))
                        {
                            symbologies.Remove(BarcodeSymbology.MicroPDF417);
                        }

                        // Try again
                        barcodes = documentPage.ReadBarcodes(request.Bounds, request.MaximumBarcodes, symbologies.ToArray());
                    }

                    // If we found any barcodes, parse the ECI data if available
                    foreach (var barcode in barcodes)
                    {
                        if (barcode.Symbology == BarcodeSymbology.QR || barcode.Symbology == BarcodeSymbology.MicroQR)
                        {
                            string eciData = BarcodeData.ParseECIData(barcode.GetData());
                            if (!string.IsNullOrEmpty(eciData))
                            {
                                barcode.Value = eciData;
                            }
                        }
                    }

                    return(new ReadBarcodesResponse {
                        Barcodes = barcodes
                    });
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(string.Format("ReadBarcodes - Error:{1}{0}documentId:{2} pageNumber:{3}", Environment.NewLine, ex.Message, request.DocumentId, pageNumber), "Error");
                throw;
            }
        }
Beispiel #26
0
        static void Main(string[] args)
        {
            // provide drivers license file with PDF417 barcode to recognize
            string inputFilePath = @"PATH TO IMAGE";

            RasterSupport.SetLicense(@"C:\LEADTOOLS 20\Common\License\LEADTOOLS.LIC", System.IO.File.ReadAllText(@"C:\LEADTOOLS 20\Common\License\LEADTOOLS.LIC.KEY"));

            using (RasterCodecs codecs = new RasterCodecs())
                using (RasterImage inputImage = codecs.Load(inputFilePath))
                {
                    BarcodeEngine engine = new BarcodeEngine();
                    BarcodeData   data   = engine.Reader.ReadBarcode(inputImage, LeadRect.Empty, BarcodeSymbology.PDF417);
                    if (data != null)
                    {
                        using (AAMVAID id = BarcodeData.ParseAAMVAData(data.GetData(), false))
                        {
                            if (id != null)
                            {
                                Console.WriteLine("Issuer Identification Number: " + id.IssuerIdentificationNumber);
                                Console.WriteLine("Jurisdiction: " + id.Jurisdiction.ToString());
                                Console.WriteLine("AAMVA CDS Version: " + id.Version.ToString());
                                Console.WriteLine("Jurisdiction Version: " + id.JurisdictionVersion);
                                Console.WriteLine("Number of Entries: " + id.NumberOfEntries.ToString());

                                AAMVANameResult firstNameResult = id.FirstName;
                                if (firstNameResult != null)
                                {
                                    Console.WriteLine("First Name: " + firstNameResult.Value + ", Inferred?: " + firstNameResult.InferredFromFullName);
                                }

                                AAMVANameResult lastNameResult = id.LastName;
                                if (lastNameResult != null)
                                {
                                    Console.WriteLine("Last Name: " + lastNameResult.Value + ", Inferred?: " + lastNameResult.InferredFromFullName);
                                }

                                string addressStreet1 = id.AddressStreet1;
                                if (addressStreet1 != null)
                                {
                                    Console.WriteLine("Address Street 1: " + addressStreet1);
                                }

                                string addressStreet2 = id.AddressStreet2;
                                if (addressStreet2 != null)
                                {
                                    Console.WriteLine("Address Street 2: " + addressStreet2);
                                }

                                string addressStateAbbreviation = id.AddressStateAbbreviation;
                                if (addressStateAbbreviation != null)
                                {
                                    Console.WriteLine("Address State Abbreviation: " + addressStateAbbreviation);
                                }

                                string addressCity = id.AddressCity;
                                if (addressCity != null)
                                {
                                    Console.WriteLine("Address City: " + addressCity);
                                }

                                string addressPostalCode = id.AddressPostalCode;
                                if (addressPostalCode != null)
                                {
                                    Console.WriteLine("Address Postal Code: " + addressPostalCode);
                                }

                                AAMVARegion addressRegion = id.AddressRegion;
                                Console.WriteLine("Address Region: " + addressRegion.ToString());

                                string dateOfBirth = id.DateOfBirth;
                                if (dateOfBirth != null)
                                {
                                    Console.WriteLine("Date of Birth: " + dateOfBirth);
                                }

                                if (id.Over18Available)
                                {
                                    Console.WriteLine("Over 18?: " + id.Over18);
                                }

                                if (id.Over19Available)
                                {
                                    Console.WriteLine("Over 19?: " + id.Over19);
                                }

                                if (id.Over21Available)
                                {
                                    Console.WriteLine("Over 21?: " + id.Over21);
                                }

                                if (id.ExpirationAvailable)
                                {
                                    Console.WriteLine("Expired?: " + id.Expired);
                                }

                                string expirationDate = id.ExpirationDate;
                                if (expirationDate != null)
                                {
                                    Console.WriteLine("Expiration Date: " + expirationDate);
                                }

                                string issueDate = id.IssueDate;
                                if (issueDate != null)
                                {
                                    Console.WriteLine("Issue Date: " + issueDate);
                                }

                                string idNumber = id.Number;
                                if (idNumber != null)
                                {
                                    Console.WriteLine("ID Number: " + idNumber);
                                }

                                AAMVAEyeColor eyeColor = id.EyeColor;
                                Console.WriteLine("Eye Color: " + eyeColor.ToString());

                                AAMVAHairColor hairColor = id.HairColor;
                                Console.WriteLine("Hair Color: " + hairColor.ToString());

                                AAMVASex sex = id.Sex;
                                Console.WriteLine("Sex: " + sex.ToString());
                                Console.ReadLine();
                            }
                        }
                    }
                }
        }
Beispiel #27
0
        private void Reader_ReadSymbology(object sender, BarcodeReadSymbologyEventArgs e)
        {
            bool   firstInGroup;
            double ms = 0;

            switch (e.Operation)
            {
            case BarcodeReadSymbologyOperation.PreRead:
                UpdateMessageLabel(e.Options);
                _stopWatch.Start();
                break;

            case BarcodeReadSymbologyOperation.PostRead:
                if (_stopWatch.IsRunning)
                {
                    _stopWatch.Stop();
                    ms = _stopWatch.ElapsedMilliseconds;
                    _stopWatch.Reset();
                    firstInGroup = true;
                }
                else
                {
                    firstInGroup = false;
                }

                // Add this item to the list
                if (e.Data != null)
                {
                    if (firstInGroup)
                    {
                        ListViewGroup group = new ListViewGroup(string.Format(DemosGlobalization.GetResxString(GetType(), "Resx_GroupRead"), ms));
                        _barcodesListView.Groups.Add(group);
                    }

                    ListViewItem item = new ListViewItem();
                    item.Text = _currentPageNumber.ToString();
                    item.SubItems.Add(BarcodeEngine.GetSymbologyFriendlyName(e.Data.Symbology));

                    string value    = string.Empty;
                    string location = string.Empty;

                    BarcodeData data = e.Data;
                    if (data != null)
                    {
                        value = data.Value;
                        if (value == null)
                        {
                            value = string.Empty;
                        }

                        location = string.Format("{0}, {1}, {2}, {3}", data.Bounds.Left, data.Bounds.Top, data.Bounds.Right, data.Bounds.Bottom);
                    }
                    else if (e.Error != null)
                    {
                        value = e.Error.Message;
                    }

                    // Parse the QR barcodes for ECI data
                    string eciData = null;
                    if (data.Symbology == BarcodeSymbology.QR || data.Symbology == BarcodeSymbology.MicroQR)
                    {
                        eciData = BarcodeData.ParseECIData(data.GetData());
                    }

                    if (!string.IsNullOrEmpty(eciData))
                    {
                        item.SubItems.Add(eciData);
                    }
                    else
                    {
                        item.SubItems.Add(value);
                    }

                    item.SubItems.Add(location);

                    item.Group = _barcodesListView.Groups[_barcodesListView.Groups.Count - 1];
                    _barcodesListView.Items.Add(item);
                }
                break;
            }

            Application.DoEvents();

            if (_isAborted)
            {
                e.Status = BarcodeReadSymbologyStatus.Abort;
            }
        }
Beispiel #28
0
        private void btnAutoDetect_Click(object sender, EventArgs e)
        {
            DetectBarcodeOperation bo = new DetectBarcodeOperation(image, bcff.Bounds);

            bo.Start();

            if (bo.IsSymbologyDetected)
            {
                BarcodeFriendlySymbology bfs = new BarcodeFriendlySymbology(bo.DetectedSymbology, BarcodeEngine.GetSymbologyFriendlyName(bo.DetectedSymbology));
                cboxSymbology.SelectedItem = bfs;
            }
            else
            {
                MessageBox.Show("Unable to determine symbology.");
            }
        }
Beispiel #29
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "Recognition/ExtractAllBarcodes")] HttpRequestMessage req, TraceWriter log, ExecutionContext context)
        {
            try
            {
                if (!DemoConfiguration.UnlockSupport(log))
                {
                    return(GenerateErrorMessage(ApiError.LicenseNotSet, req));
                }

                var leadParameterObject = ParseLeadWebRequestParameters(req);
                if (!leadParameterObject.Successful)
                {
                    return(GenerateErrorMessage(ApiError.InvalidRequest, req));
                }

                var barcodeList = ExtractBarcodeSymbologies(req);
                if (barcodeList.Count == 0)
                {
                    return(GenerateErrorMessage(ApiError.InvalidRequest, req));
                }

                var imageReturn = await GetImageStreamAsync(leadParameterObject.LeadWebRequest.fileUrl, req, DemoConfiguration.MaxUrlMbs);

                if (!imageReturn.Successful)
                {
                    return(GenerateErrorMessage(imageReturn.ErrorType.Value, req));
                }

                using (imageReturn.Stream)
                {
                    LoadDocumentOptions options = new LoadDocumentOptions()
                    {
                        FirstPageNumber = leadParameterObject.LeadWebRequest.FirstPage,
                        LastPageNumber  = leadParameterObject.LeadWebRequest.LastPage
                    };

                    RecognitionEngine recognitionEngine = new RecognitionEngine();
                    recognitionEngine.WorkingDirectory = Path.GetTempPath();
                    BarcodeEngine            barcodeEngine  = new BarcodeEngine();
                    var                      barcodeResults = recognitionEngine.ExtractBarcode(imageReturn.Stream, options, barcodeEngine, barcodeList.ToArray(), 0, true);
                    List <BarcodeResultData> results        = new List <BarcodeResultData>();
                    foreach (var pageBarcodeData in barcodeResults)
                    {
                        foreach (var d in pageBarcodeData.BarcodeData)
                        {
                            if (d != null && d.Value != null)
                            {
                                var rect = new Rectangle(d.Bounds.X, d.Bounds.Y, d.Bounds.Width, d.Bounds.Height);
                                results.Add(new BarcodeResultData(pageBarcodeData.PageNumber, d.Symbology.ToString(), d.Value, rect, d.RotationAngle));
                            }
                        }
                    }
                    var returnRequest = req.CreateResponse(HttpStatusCode.OK);
                    returnRequest.Content = new StringContent(JsonConvert.SerializeObject(results));
                    return(returnRequest);
                }
            }
            catch (Exception ex)
            {
                log.Error($"API Error occurred for request: {context.InvocationId} \n Details: {JsonConvert.SerializeObject(ex)}");
                return(GenerateErrorMessage(ApiError.InternalServerError, req));
            }
        }
Beispiel #30
0
        private bool ReadIDBarcode(BarcodeDirectionFlags direction, ref string Barcode)
        {
            //Validate General
            _readMaxBarcodesCount = 1;
            _unit = (BarcodeUnit.Millimeters);

            //Validate Location
            _readArea  = new LeadRect(0, 0, 0, 0);
            _useRegion = false;

            //Validate Color
            _useColor = false;

            _barcodeReadColor            = new BarcodeColor();
            _barcodeReadColor.BarColor   = FromGdiPlusColor(Color.Black);
            _barcodeReadColor.SpaceColor = FromGdiPlusColor(Color.White);

            //Validate All Tab controls
            SetToReadStandard1DControls(direction);

            _barcodeReadFlags = 0;
            if (_useColor)
            {
                _barcodeReadFlags |= BarcodeReadFlags.UseColors;
            }


            if (bSearchAllStd1D)
            {
                _readBarcodeTypes = BarcodeSearchTypeFlags.Barcode1dReadAnyType;
            }
            else if (bSearchAllNoRSS)
            {
                _readBarcodeTypes = BarcodeSearchTypeFlags.Barcode1dReadAnyTypeNoRss14;
            }
            else
            {
                _readBarcodeTypes = ulSearchStd1DType;
            }

            _barcodeReadFlags |= uFlags_Std1DPg;
            _barcodeRead1d     = StdBar1D;
            _barcodeReadPDF    = new BarcodeReadPdf();


            try
            {
                LeadRect area = LeadRect.Empty;
                if (_useRegion)
                {
                    area = LeadRect.Empty;
                }
                else
                {
                    if (_readArea == LeadRect.Empty)
                    {
                        area = new LeadRect(0, 0, _viewer.Image.Width, _viewer.Image.Height);
                    }
                    else
                    {
                        area = _readArea;
                    }
                }
                RasterCollection <BarcodeData> barcodeData = new RasterCollection <BarcodeData>();
                _barcodeEngine = new BarcodeEngine();

                barcodeData = _barcodeEngine.Read(_viewer.Image,
                                                  area,
                                                  _readBarcodeTypes,
                                                  _unit,
                                                  _barcodeReadFlags,
                                                  _readMaxBarcodesCount,
                                                  _barcodeRead1d,
                                                  _barcodeReadPDF,
                                                  _barcodeReadColor);

                //string msg;
                //msg = string.Format("Total Bar Code Symbols Found is: {0}", barcodeData.Count);

                RasterCollection <BarcodeData> _barcodeDataCollection;
                _barcodeDataCollection = barcodeData;
                BarcodeData data = (BarcodeData)_barcodeDataCollection[0];

                // Extract the barcode data string
                byte[] screenData = new byte[data.Data.Length];
                for (int dataIndex = 0, screenIndex = 0; dataIndex < data.Data.Length; dataIndex++)
                {
                    if (data.Data[dataIndex] != 0)
                    {
                        //if 3 then change to 32(space)
                        screenData[screenIndex] = data.Data[dataIndex] < (byte)32 ? (byte)32 : data.Data[dataIndex];
                        screenIndex++;
                    }
                }
                string dataString = BarcodeData.ConvertToStringArray(screenData)[0];
                Barcode = dataString;
            }
            catch (BarcodeException ex)
            {
                if (ex.Code == BarcodeExceptionCode.NotFound)
                {
                    Barcode = "barcode not found";
                    return(false);
                }
                else
                {
                    throw;   // MessageBox.Show(ex.Message);
                }
            }
            catch      //(Exception ex)
            {
                throw; //MessageBox.Show(ex.Message);
            }
            return(true);
        }