// Gets selected barcode type private BarcodeTypeSelector GetBarcodeTypeFromCombobox() { BarcodeTypeSelector result = new BarcodeTypeSelector(); string selectedBarcodeTypeName = (string)cmbBarcodeType.SelectedItem; PropertyInfo propertyInfo = typeof(BarcodeTypeSelector).GetProperty(selectedBarcodeTypeName); propertyInfo.SetValue(result, true, null); return(result); }
/// <summary> /// Get symbology filter for the SDK from the combobox selection text /// </summary> /// <param name="barType"></param> /// <returns></returns> private static BarcodeTypeSelector GetBarcodeTypeToFindFromCombobox(string barType) { string selectedItemText = barType.Trim().ToUpper(); BarcodeTypeSelector barcodeTypeToScan = new BarcodeTypeSelector(); if (selectedItemText.IndexOf("ALL BARCODES") > -1) barcodeTypeToScan.SetAll(); else if (selectedItemText.IndexOf("ALL LINEAR BARCODES") > -1) barcodeTypeToScan.SetAll1D(); else if (selectedItemText.IndexOf("ALL 2D BARCODES") > -1) barcodeTypeToScan.SetAll2D(); else if (selectedItemText.IndexOf("AZTEC") > -1) barcodeTypeToScan.Aztec = true; else if (selectedItemText.IndexOf("CODABAR") > -1) barcodeTypeToScan.Codabar = true; else if (selectedItemText.IndexOf("CODE 39") > -1) barcodeTypeToScan.Code39 = true; else if (selectedItemText.IndexOf("CODE 128") > -1) barcodeTypeToScan.Code128 = true; else if (selectedItemText.IndexOf("DATAMATRIX") > -1) barcodeTypeToScan.DataMatrix = true; else if (selectedItemText.IndexOf("EAN 13") > -1) barcodeTypeToScan.EAN13 = true; else if (selectedItemText.IndexOf("GS1-128") > -1) barcodeTypeToScan.GS1 = true; else if (selectedItemText.IndexOf("GS1DATABAREXPANDED") > -1) barcodeTypeToScan.GS1DataBarExpanded = true; else if (selectedItemText.IndexOf("GS1DATABAREXPANDEDSTACKED") > -1) barcodeTypeToScan.GS1DataBarExpandedStacked = true; else if (selectedItemText.IndexOf("GS1DATABARLIMITED") > -1) barcodeTypeToScan.GS1DataBarLimited = true; else if (selectedItemText.IndexOf("GS1DATABAROMNIDIRECTIONAL") > -1) barcodeTypeToScan.GS1DataBarOmnidirectional = true; else if (selectedItemText.IndexOf("GS1DATABARSTACKED") > -1) barcodeTypeToScan.GS1DataBarStacked = true; else if (selectedItemText.IndexOf("I2OF5") > -1) barcodeTypeToScan.Interleaved2of5 = true; else if (selectedItemText.IndexOf("PATCH") > -1) barcodeTypeToScan.PatchCode = true; else if (selectedItemText.IndexOf("PDF 417") > -1) barcodeTypeToScan.PDF417 = true; else if (selectedItemText.IndexOf("QR CODE") > -1) barcodeTypeToScan.QRCode = true; else if (selectedItemText.IndexOf("UPCA") > -1) barcodeTypeToScan.UPCA = true; else if (selectedItemText.IndexOf("UPCE") > -1) barcodeTypeToScan.UPCE = true; else if (selectedItemText.IndexOf("MAXICODE") > -1) barcodeTypeToScan.MaxiCode = true; return barcodeTypeToScan; }
// Background thread procedure used by BackgroundWorker public void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = (BackgroundWorker)sender; BarcodeTypeSelector barcodeTypesToFind = (BarcodeTypeSelector)e.Argument; // Create and setup barcode reader instance using (Reader reader = new Reader()) { reader.RegistrationName = "demo"; reader.RegistrationKey = "demo"; reader.BarcodeTypesToFind = barcodeTypesToFind; // Work while not canceled while (true) { // Check cancellation if (worker.CancellationPending) { e.Cancel = true; _synchronizationEvent.Set(); return; } // Get image from camera by invoking method from UI thread Bitmap bitmap = (Bitmap)Invoke(new GetCameraImageDelegate(GetCameraImage)); if (bitmap == null) { e.Result = null; return; } /* ----------------------------------------------------------------------- * NOTE: We can read barcodes from specific page to increase performance. * For sample please refer to "Decoding barcodes from PDF by pages" program. * ----------------------------------------------------------------------- */ // Search the image for barcodes FoundBarcode[] result = reader.ReadFrom(bitmap); // Update UI asynchronously BeginInvoke(new Action <FoundBarcode[]>(UpdateStatus), new object[] { result }); // Pause Thread.Sleep(SCAN_DELAY); } } }
public void StartDecoding() { if (cmbCamera.SelectedIndex == -1) { return; } // Clear the output text box rtbFoundBarcodes.Clear(); // Check if we have camera selected if (cmbCamera.SelectedIndex != -1) { // Start the decoding in the background thread BarcodeTypeSelector barcodeTypesToFind = GetBarcodeTypeFromCombobox(); _backgroundWorker.RunWorkerAsync(barcodeTypesToFind); UpdateControls(true); } else { MessageBox.Show("Please select the camera first!"); } }