internal string readFromStream(string fileName) { CiBarcodePro reader = null; try { CiServer ci = Inlite.ClearImageNet.Server.GetThreadServer(); reader = ci.CreateBarcodePro(); if (tbrCode != 0) { reader.TbrCode = tbrCode; // ClearImage V9 and later. Otherwise use: reader.Encodings = (EBarcodeEncoding) tbrCode; } // for faster reading specify only required direction reader.Directions = FBarcodeDirections.cibHorz | FBarcodeDirections.cibVert | FBarcodeDirections.cibDiag; //configure types reader.Type = FBarcodeType.cibfCode128 | FBarcodeType.cibfCode39; using (MemoryStream ms = Utility.FileToStream(fileName)) { int page = 1; reader.Image.Open(ms, 1); int cnt = 0; string s = ""; while (reader.Image.IsValid) { reader.Find(0); foreach (CiBarcode bc in reader.Barcodes) { cnt++; AddBarcode(ref s, cnt, bc, reader.Image.FileName, page); } page++; if (page > reader.Image.PageCount) { break; } reader.Image.OpenPage(page); if (cnt == 0) { s = s + "NO BARCODES"; } s = s + Environment.NewLine; } return(s); } } catch (Exception ex) { return(ex.Message); } finally { if (reader != null) { reader.Image.Close(); // ClearImage V9 and later. Immediately free memory } } }
internal string read1DautoType(string fileName, int page) { CiBarcodePro reader = null; try { CiServer ci = Inlite.ClearImageNet.Server.GetThreadServer(); reader = ci.CreateBarcodePro(); if (tbrCode != 0) { reader.TbrCode = tbrCode; // ClearImage V9 and later. Otherwise use: reader.Encodings = (EBarcodeEncoding) tbrCode; } // for faster reading specify only required direction reader.Directions = FBarcodeDirections.cibHorz | FBarcodeDirections.cibVert | FBarcodeDirections.cibDiag; //configure types reader.AutoDetect1D = true; reader.Image.Open(fileName, page); reader.Find(0); int cnt = 0; string s = ""; foreach (CiBarcode bc in reader.Barcodes) { cnt++; AddBarcode(ref s, cnt, bc, reader.Image.FileName, reader.Image.PageNumber); } if (cnt == 0) { s = s + "NO BARCODES"; } s = s + Environment.NewLine; return(s); } catch (Exception ex) { return(ex.Message); } finally { if (reader != null) { reader.Image.Close(); // ClearImage V9 and later. Immediately free memory } } }
private void Read1DPro_OnThread() { CiBarcodePro reader = null; try { CiServer ci = Inlite.ClearImageNet.Server.GetThreadServer(); reader = ci.CreateBarcodePro(); if (tbrCode != 0) { reader.TbrCode = tbrCode; // ClearImage V9 and later. Otherwise use: reader.Encodings = (EBarcodeEncoding) tbrCode; } // for faster reading specify only required direction reader.Directions = FBarcodeDirections.cibHorz | FBarcodeDirections.cibVert | FBarcodeDirections.cibDiag; //configure types reader.Type = FBarcodeType.cibfCode128 | FBarcodeType.cibfCode39; // Read while (true) { string fileName; // Obtain next file name lock (_lockObject) { if (filesScanned >= filesToScan.Length) { break; } fileName = filesToScan[filesScanned]; filesScanned++; } // Read images from file string s = ""; try { // Disable zone int page = 1; reader.Image.Open(fileName, 1); while (reader.Image.IsValid) { reader.Find(0); int cnt = 0; foreach (CiBarcode bc in reader.Barcodes) { cnt++; AddBarcode(ref s, cnt, bc, reader.Image.FileName, page); } page++; if (page > reader.Image.PageCount) { break; } reader.Image.Open(fileName, page); } // update display lock (_lockObject) { if (s != "") { string s1 = txtRslt.Text + "_OnBarcodeFound on Managed Thread " + System.Threading.Thread.CurrentThread.ManagedThreadId + " -> " + Environment.NewLine + s; SetControlPropertyThreadSafe(txtRslt, "Text", s); } System.Windows.Forms.Application.DoEvents(); } } catch (Exception ex) { string s1 = txtRslt.Text + ">>>>>>>> ERROR processing '" + fileName + "'" + Environment.NewLine + ex.Message + Environment.NewLine; lock (_lockObject) { SetControlPropertyThreadSafe(txtRslt, "Text", s1); System.Windows.Forms.Application.DoEvents(); } } } } catch (Exception ex) { string s1 = txtRslt.Text + ">>>>>>>> ERROR processing '" + Environment.NewLine + ex.Message + Environment.NewLine; lock (_lockObject) { SetControlPropertyThreadSafe(txtRslt, "Text", s1); System.Windows.Forms.Application.DoEvents(); } } finally { if (reader != null) { reader.Image.Close(); // ClearImage V9 and later. Immediately free memory } } }
internal string readWithZones(string fileName, int page) { CiBarcodePro reader = null; try { CiServer ci = Inlite.ClearImageNet.Server.GetThreadServer(); reader = ci.CreateBarcodePro(); if (tbrCode != 0) { reader.TbrCode = tbrCode; // ClearImage V9 and later. Otherwise use: reader.Encodings = (EBarcodeEncoding) tbrCode; } // for faster reading specify only required direction reader.Directions = FBarcodeDirections.cibHorz | FBarcodeDirections.cibVert | FBarcodeDirections.cibDiag; //configure types reader.Type = FBarcodeType.cibfCode128 | FBarcodeType.cibfCode39; CiImage image = ci.CreateImage(); string st = image.FileName; image.Open(fileName, page); string s = "======= Barcode in ZONE (upper half of the image) ===========" + Environment.NewLine; // Set zone to top half of the image reader.Image = image.CreateZone(0, 0, image.Width, image.Height / 2); reader.Find(0); int cnt = 0; foreach (CiBarcode bc in reader.Barcodes) { cnt++; AddBarcode(ref s, cnt, bc, image.FileName, image.PageNumber); } if (cnt == 0) { s = s + "NO BARCODES"; } s = s + Environment.NewLine; s = s + "======= Barcode in IMAGE ===========" + Environment.NewLine; // Disable zone reader.Image = image; reader.Find(0); cnt = 0; foreach (CiBarcode bc in reader.Barcodes) { cnt++; AddBarcode(ref s, cnt, bc, image.FileName, image.PageNumber); } if (cnt == 0) { s = s + "NO BARCODES"; } s = s + Environment.NewLine; return(s); } catch (Exception ex) { return(ex.Message); } finally { if (reader != null) { reader.Image.Close(); // ClearImage V9 and later. Immediately free memory } } }