/// <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(); }
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; } }
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; } }