private void ReadBarcode(Bitmap bitmap) { // Read barcodes with Dynamsoft Barcode Reader Stopwatch sw = Stopwatch.StartNew(); sw.Start(); TextResult[] results = _barcodeReader.DecodeBitmap(bitmap, ""); sw.Stop(); Console.WriteLine(sw.Elapsed.TotalMilliseconds + "ms"); bitmap.Dispose(); // Clear previous results textBox1.Clear(); if (results == null) { textBox1.Text = "No barcode detected!"; return; } // Display barcode results foreach (TextResult result in results) { textBox1.AppendText(result.BarcodeText + "\n"); textBox1.AppendText("\n"); } }
public static BarcodeResult[] GetBarcode(Bitmap bitmap, Int64 format, string strSessionID) { BarcodeReader reader = new BarcodeReader(); ReaderOptions options = new ReaderOptions(); options.MaxBarcodesToReadPerPage = 100; options.BarcodeFormats = (BarcodeFormat)format; reader.ReaderOptions = options; reader.LicenseKeys = "<input barcode reader license here>"; return reader.DecodeBitmap(bitmap); }
public static BarcodeResult[] GetBarcode(Bitmap bitmap, Int64 format, string strSessionID) { BarcodeReader reader = new BarcodeReader(); ReaderOptions options = new ReaderOptions(); options.MaxBarcodesToReadPerPage = 100; options.BarcodeFormats = (BarcodeFormat)format; reader.ReaderOptions = options; reader.LicenseKeys = "<input barcode reader license here>"; return(reader.DecodeBitmap(bitmap)); }
public string[] ReadBarcode(Bitmap bitmap) { TextResult[] textResults = mBarcodeReader.DecodeBitmap(bitmap, ""); if (textResults != null) { string[] results = new string[textResults.Length]; int index = 0; foreach (TextResult result in textResults) { results[index++] = result.BarcodeText; } return(results); } return(null); }
private void Barcode_Click(object sender, RoutedEventArgs e) { if (m_CoreForImageThum.ImageBuffer.HowManyImagesInBuffer > 0) { try { BarcodeReader m_BarcodeReader = new BarcodeReader(); m_BarcodeReader.LicenseKeys = m_StrProductKey; m_BarcodeReader.LoadSettingsFromFile(mSettingsPath + "template_aggregation.json"); Bitmap bmp = (Bitmap)(m_CoreForImageThum.ImageBuffer.GetBitmap(m_CoreForImageThum.ImageBuffer.CurrentImageIndexInBuffer)); DateTime beforeRead = DateTime.Now; TextResult[] aryResult = m_BarcodeReader.DecodeBitmap(bmp, "All_DEFAULT"); DateTime afterRead = DateTime.Now; int timeElapsed = (int)(afterRead - beforeRead).TotalMilliseconds; this.ShowResult(aryResult, timeElapsed); } catch (Exception exp) { MessageBox.Show(exp.Message, "Decoding Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private void Barcode_Click(object sender, RoutedEventArgs e) { if (m_CoreForImageThum.ImageBuffer.HowManyImagesInBuffer > 0) { System.Drawing.Bitmap bmp = null; try { BarcodeReader reader = new BarcodeReader(); reader.LicenseKeys = m_StrProductKey; BarcodeResult[] aryResult = reader.DecodeBitmap(m_CoreForImageThum.ImageBuffer.GetBitmap(m_CoreForImageThum.ImageBuffer.CurrentImageIndexInBuffer)); if (aryResult == null) { string strResult = "The barcode for selected format is not found." + "\r\n"; MessageBox.Show(strResult, "Barcodes Results"); } else { string strResult = aryResult.Length + " total barcode found." + "\r\n"; for (int i = 0; i < aryResult.Length; i++) { strResult += String.Format("Result {0}\r\n Barcode Format: {1} Barcode Text: {2}\r\n", (i + 1), aryResult[i].BarcodeFormat, aryResult[i].BarcodeText); } MessageBox.Show(strResult, "Barcodes Results"); } } catch (Exception exp) { MessageBox.Show(exp.Message, "Decoding Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { if (bmp != null) { bmp.Dispose(); } } } }
private Result ScanBitmap(WriteableBitmap writeableBmp) { var barcodeReader = new BarcodeReader { AutoRotate = true, Options = new DecodingOptions { TryHarder = true, // restrict to one or more supported types, if necessary //PossibleFormats = new [] // { // BarcodeFormat.QR_CODE // } } }; var result = barcodeReader.DecodeBitmap(writeableBmp); if (result != null) { CaptureImage.Source = writeableBmp; } return(result); }
private void timer1_Tick(object sender, EventArgs e) { if (m_CurrentCamera != null) { Bitmap tempBmp = m_CurrentCamera.GrabImage(); m_ImageCore.IO.LoadImage(tempBmp); try { BarcodeReader dbr = new BarcodeReader(); dbr.LicenseKeys = "t0068UwAAAIcVCMR0LfYuOyMnEOjUBCwp0Ic58BqPnpK9L6GdbLRj1OctKZzfOueNck25ncqc/GjhaduvqDSm8J6/4t4LWlA="; TextResult[] aryResult = dbr.DecodeBitmap(tempBmp, ""); // leave the template name empty ("") will use default settings for recognition if (aryResult.Length == 0) { Console.WriteLine("No barcode found."); } else { for (var i = 0; i < aryResult.Length; i++) { // Console.WriteLine("Barcode: {0}", (i + 1)); // Console.WriteLine("BarcodeFormat: {0}", aryResult[i].BarcodeFormat.ToString()); //MessageBox.Show(aryResult[i].BarcodeText); TextWriter txt = new StreamWriter("demo"); txt.Write(aryResult[i].BarcodeText); txt.Close(); this.Hide(); } } } catch (BarcodeReaderException exp) { Console.WriteLine("Error: {0}, {1}", exp.Code.ToString(), exp.Message); } /* * string[] datas = BarcodeScanner.Scan(tempBmp, BarcodeType.QRCode); * * // string[] barcodeValues = BarcodeReader.read(tempBmp, KeepDynamic.BarcodeReader.Type.QRCode); * //BarcodeResult Result = IronBarCode.BarcodeReader.ReadASingleBarcode("aa.png", BarcodeEncoding.QRCode | BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.High, BarcodeReader.BarcodeImageCorrection.MediumCleanPixels); * // BarcodeResult r1 = IronBarCode.BarcodeReader.ReadASingleBarcode(tempBmp, BarcodeEncoding.All); * if (datas != null) * { * MessageBox.Show(datas.ToString()); * * TextWriter txt = new StreamWriter("demo.txt"); * txt.Write(datas.ToString()); * txt.Close(); * //Bank toMain = new Bank(); * //toMain.Test = r1.Text; * //this.Close(); * // toMain.Show(); * // MessageBox.Show(bank.q); * //Application.Restart(); * //if (toMain.ShowDialog() == DialogResult.Cancel) * //{ * // toMain.Close(); * //} * //this.parent = bank; * //this.parent.Show(); * Application.Exit(); * } */ m_ImageCore.ImageBuffer.RemoveAllImages(); } }
/// <summary> /// Using barcode value to rename documents. /// </summary> /// <param name="strInputFolder">the path of folder that documents in</param> /// <param name="strOutputFolder">the path of folder that renamed documents saved in</param> private void DoRename(string strInputFolder, string strOutputFolder) { int iFileCount = 0; int iSuccCount = 0; DateTime dtStart = DateTime.Now; string[] files = Directory.GetFiles(strInputFolder); if (files != null) { foreach (string strFile in files) { if (IsImageFile(strFile)) { FileStream infs = null; FileStream outfs = null; try { iFileCount++; int iDirectSeparator = strFile.LastIndexOf(Path.DirectorySeparatorChar); string strFileName = strFile.Substring(iDirectSeparator + 1); tbLog.AppendText(string.Format("\r\nProcessing file {0}\r\n", strFileName)); Bitmap bmp = (Bitmap)Bitmap.FromFile(strFile); string[] Templates = barcodeReader.GetAllParameterTemplateNames(); bool bifcontian = false; for (int i = 0; i < Templates.Length; i++) { if (format == Templates[i]) { bifcontian = true; } } if (!bifcontian) { MessageBox.Show(("Failed to find the template named " + format + "."), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } TextResult[] barcodes = barcodeReader.DecodeBitmap(bmp, format);//DecodeFile(strFile); bmp.Dispose(); if (barcodes == null || barcodes.Length <= 0) { tbLog.AppendText("There is no barcode on the first page\r\n"); } else { tbLog.AppendText(string.Format("Page: {0}\r\n", barcodes[0].LocalizationResult.PageNumber)); tbLog.AppendText(string.Format("Barcode Value: {0}\r\n", barcodes[0].BarcodeText)); //output file name int iDot = strFileName.LastIndexOf('.'); string strOutputFileName = barcodes[0].BarcodeText + strFileName.Substring(iDot); string strOutputFile = null; if (strOutputFolder.EndsWith(Path.DirectorySeparatorChar.ToString())) { strOutputFile = strOutputFolder + strOutputFileName; } else { strOutputFile = strOutputFolder + Path.DirectorySeparatorChar + strOutputFileName; } if (barcodes[0].BarcodeText.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) { tbLog.AppendText(string.Format("{0} contains character(s) that are not allowed in file names, skip renaming\r\n", barcodes[0].BarcodeText)); } else { if (File.Exists(strOutputFile)) { tbLog.AppendText(string.Format("{0} exists, skip renaming {1}\r\n", strOutputFileName, strFileName)); } else { infs = new FileStream(strFile, FileMode.Open, FileAccess.Read); outfs = new FileStream(strOutputFile, FileMode.CreateNew); int size = 1 << 14; byte[] buffer = new byte[size]; while (infs.Read(buffer, 0, size) > 0) { outfs.Write(buffer, 0, size); } infs.Close(); outfs.Close(); iSuccCount++; tbLog.AppendText(string.Format("Renamed to {0}\r\n", strOutputFileName)); } } } } catch (Exception exp) { tbLog.AppendText(exp.Message + "\r\n"); if (infs != null) { infs.Close(); } if (outfs != null) { outfs.Close(); } } tbLog.Refresh(); } } } tbLog.AppendText("Completed\r\n"); tbLog.AppendText(string.Format("Files Total: {0} file(s), Success: {1} file(s)\r\n", iFileCount, iSuccCount)); tbLog.AppendText(string.Format("Total cost time: {0}ms", (int)(DateTime.Now - dtStart).TotalMilliseconds)); }
private void SaveFileByBegainWithBarcode() { m_listBarcodeType = new List <string>(); List <IndexList> listImageIndex = new List <IndexList>(); IndexList listIndex = null; BarcodeReader reader = new BarcodeReader(); bHasBarcodeOnFirstImage = false; reader.LicenseKeys = "91392547848AAF240620ADFEFDB2EDEB"; try { for (int i = 0; i < this.dynamicDotNetTwain1.HowManyImagesInBuffer; i++) { if (null == listIndex) { listIndex = new IndexList(); } switch (cmbBarcodeFormat.SelectedIndex) { case 0: break; case 1: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.OneD; break; case 2: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.CODE_39; break; case 3: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.CODE_128; break; case 4: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.CODE_93; break; case 5: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.CODABAR; break; case 6: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.ITF; break; case 7: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.EAN_13; break; case 8: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.EAN_8; break; case 9: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.UPC_A; break; case 10: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.UPC_E; break; case 11: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.PDF417; break; case 12: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.QR_CODE; break; case 13: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.DATAMATRIX; break; case 14: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.INDUSTRIAL_25; break; } strBarcodeFormat = reader.ReaderOptions.BarcodeFormats.ToString(); if (cmbBarcodeFormat.SelectedIndex == 0) { strBarcodeFormat = "All"; } BarcodeResult[] aryResult = null; aryResult = reader.DecodeBitmap((Bitmap)dynamicDotNetTwain1.GetImage((short)i)); if (i == 0) { if (aryResult != null) { if (aryResult.Length != 0) { bHasBarcodeOnFirstImage = true; } } } if (null == aryResult || (aryResult != null && aryResult.Length == 0)) { listIndex.Add(i); //If no barcode found on the current image, add it to the image list for saving } else { m_listBarcodeType.Add(aryResult[0].BarcodeText); if (listIndex != null && listIndex.Count > 0) { listImageIndex.Add(listIndex); listIndex = null; } //If a barcode is found, restart the list if (null == listIndex) { listIndex = new IndexList(); } listIndex.Add(i); } } if (listIndex != null) { listImageIndex.Add(listIndex); //save a last set of data listIndex = null; } SaveImages(listImageIndex); } catch (Exception exp) { MessageBox.Show(exp.Message, "Decoding error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void SaveFileByBarcodeText() { m_listBarcodeType = new List <string>(); List <IndexList> listImageIndex = new List <IndexList>(); IndexList listIndex = new IndexList(); listImageIndex.Add(listIndex); //use to save no barcode files BarcodeReader reader = new BarcodeReader(); reader.LicenseKeys = "91392547848AAF240620ADFEFDB2EDEB"; try { switch (cmbBarcodeFormat.SelectedIndex) { case 0: break; case 1: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.OneD; break; case 2: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.CODE_39; break; case 3: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.CODE_128; break; case 4: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.CODE_93; break; case 5: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.CODABAR; break; case 6: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.ITF; break; case 7: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.EAN_13; break; case 8: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.EAN_8; break; case 9: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.UPC_A; break; case 10: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.UPC_E; break; case 11: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.PDF417; break; case 12: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.QR_CODE; break; case 13: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.DATAMATRIX; break; case 14: reader.ReaderOptions.BarcodeFormats = Dynamsoft.Barcode.BarcodeFormat.INDUSTRIAL_25; break; } strBarcodeFormat = reader.ReaderOptions.BarcodeFormats.ToString(); if (cmbBarcodeFormat.SelectedIndex == 0) { strBarcodeFormat = "All"; } for (int i = 0; i < this.dynamicDotNetTwain1.HowManyImagesInBuffer; i++) { BarcodeResult[] aryResult = null; aryResult = reader.DecodeBitmap((Bitmap)dynamicDotNetTwain1.GetImage((short)i)); if (null == aryResult || (aryResult != null && aryResult.Length == 0)) { //If no barcode found on the current image, add it to the image list for saving UpdateDateList(0, i, ref listImageIndex); } else //If a barcode is found, restart the list { string strBarcodeText = aryResult[0].BarcodeText; int iPosition = 0; if (IfExistBarcodeText(strBarcodeText, out iPosition)) { UpdateDateList(iPosition, i, ref listImageIndex); } else { m_listBarcodeType.Add(strBarcodeText); AddDateList(i, ref listImageIndex); } } } SaveImages(listImageIndex); } catch (Exception exp) { MessageBox.Show(exp.Message, "Decoding error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Using barcode value to rename documents. /// </summary> /// <param name="strInputFolder">the path of folder that documents in</param> /// <param name="strOutputFolder">the path of folder that renamed documents saved in</param> private void DoRename(string strInputFolder, string strOutputFolder) { int iFileCount = 0; int iSuccCount = 0; DateTime dtStart = DateTime.Now; string[] files = Directory.GetFiles(strInputFolder); if (files != null) { foreach (string strFile in files) { if (IsImageFile(strFile)) { FileStream infs = null; FileStream outfs = null; try { iFileCount++; int iDirectSeparator = strFile.LastIndexOf(Path.DirectorySeparatorChar); string strFileName = strFile.Substring(iDirectSeparator + 1); tbLog.AppendText(string.Format("\r\nProcessing file {0}\r\n", strFileName)); Bitmap bmp = (Bitmap)Bitmap.FromFile(strFile); string strErrorMSG = ""; //Best coverage settings barcodeReader.InitRuntimeSettingsWithString("{\"ImageParameter\":{\"Name\":\"BestCoverage\",\"DeblurLevel\":9,\"ExpectedBarcodesCount\":512,\"ScaleDownThreshold\":100000,\"LocalizationModes\":[{\"Mode\":\"LM_CONNECTED_BLOCKS\"},{\"Mode\":\"LM_SCAN_DIRECTLY\"},{\"Mode\":\"LM_STATISTICS\"},{\"Mode\":\"LM_LINES\"},{\"Mode\":\"LM_STATISTICS_MARKS\"}],\"GrayscaleTransformationModes\":[{\"Mode\":\"GTM_ORIGINAL\"},{\"Mode\":\"GTM_INVERTED\"}]}}", EnumConflictMode.CM_OVERWRITE, out strErrorMSG); //Best speed settings //barcodeReader.InitRuntimeSettingsWithString("{\"ImageParameter\":{\"Name\":\"BestSpeed\",\"DeblurLevel\":3,\"ExpectedBarcodesCount\":512,\"LocalizationModes\":[{\"Mode\":\"LM_SCAN_DIRECTLY\"}],\"TextFilterModes\":[{\"MinImageDimension\":262144,\"Mode\":\"TFM_GENERAL_CONTOUR\"}]}}", EnumConflictMode.CM_OVERWRITE, out strErrorMSG); //Balance settings //barcodeReader.InitRuntimeSettingsWithString("{\"ImageParameter\":{\"Name\":\"Balance\",\"DeblurLevel\":5,\"ExpectedBarcodesCount\":512,\"LocalizationModes\":[{\"Mode\":\"LM_CONNECTED_BLOCKS\"},{\"Mode\":\"LM_STATISTICS\"}]}}", EnumConflictMode.CM_OVERWRITE, out strErrorMSG); PublicRuntimeSettings tempParameterSettings = barcodeReader.GetRuntimeSettings(); tempParameterSettings.BarcodeFormatIds = formatid; barcodeReader.UpdateRuntimeSettings(tempParameterSettings); TextResult[] barcodes = barcodeReader.DecodeBitmap(bmp, "");//DecodeFile(strFile); bmp.Dispose(); if (barcodes == null || barcodes.Length <= 0) { tbLog.AppendText("There is no barcode on the first page\r\n"); } else { tbLog.AppendText(string.Format("Page: {0}\r\n", barcodes[0].LocalizationResult.PageNumber)); tbLog.AppendText(string.Format("Barcode Value: {0}\r\n", barcodes[0].BarcodeText)); //output file name int iDot = strFileName.LastIndexOf('.'); string strOutputFileName = barcodes[0].BarcodeText + strFileName.Substring(iDot); string strOutputFile = null; if (strOutputFolder.EndsWith(Path.DirectorySeparatorChar.ToString())) { strOutputFile = strOutputFolder + strOutputFileName; } else { strOutputFile = strOutputFolder + Path.DirectorySeparatorChar + strOutputFileName; } if (barcodes[0].BarcodeText.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) { tbLog.AppendText(string.Format("{0} contains character(s) that are not allowed in file names, skip renaming\r\n", barcodes[0].BarcodeText)); } else { if (File.Exists(strOutputFile)) { tbLog.AppendText(string.Format("{0} exists, skip renaming {1}\r\n", strOutputFileName, strFileName)); } else { infs = new FileStream(strFile, FileMode.Open, FileAccess.Read); outfs = new FileStream(strOutputFile, FileMode.CreateNew); int size = 1 << 14; byte[] buffer = new byte[size]; while (infs.Read(buffer, 0, size) > 0) { outfs.Write(buffer, 0, size); } infs.Close(); outfs.Close(); iSuccCount++; tbLog.AppendText(string.Format("Renamed to {0}\r\n", strOutputFileName)); } } } } catch (Exception exp) { tbLog.AppendText(exp.Message + "\r\n"); if (infs != null) { infs.Close(); } if (outfs != null) { outfs.Close(); } } tbLog.Refresh(); } } } tbLog.AppendText("Completed\r\n"); tbLog.AppendText(string.Format("Files Total: {0} file(s), Success: {1} file(s)\r\n", iFileCount, iSuccCount)); tbLog.AppendText(string.Format("Total cost time: {0}ms", (int)(DateTime.Now - dtStart).TotalMilliseconds)); }