private void btnGetBarcode_Click(object sender, EventArgs e) { string filePath = @"D:\Thietke.Ck\TPAD.M\TPAD.M5211.Ck\BCCk.TPAD.M5211\BC-CAD.TPAD.M5211\TPAD.M5211.01.01.01.jpg"; OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() == DialogResult.OK) { filePath = ofd.FileName; } System.Drawing.Image img = System.Drawing.Image.FromFile(filePath); Bitmap mBitmap = new Bitmap(img); ArrayList barcodes = new ArrayList(); BarcodeImaging.FullScanPage(ref barcodes, mBitmap, 100); mBitmap.Dispose(); if (barcodes.Count > 0) { textBox1.Text = barcodes.ToArray()[0].ToString(); } else { MessageBox.Show("Không tìm thấy barcode!"); } }
private void btnScan_Click(object sender, EventArgs e) { Bitmap imgBarCode = new Bitmap("images/barcode2.jpg"); //string barCode = BarcodeImaging.ReadCode39(imgBarCode, 0, imgBarCode.Height); BarcodeImaging.FullScanPage(ref barCodes, imgBarCode, 100); if (barCodes.Count > 0)//found barcode { } //else //check more images for a barcode }
public static ArrayList ScanImgForBarcode(System.Drawing.Bitmap image) { if (image == null) { throw new ArgumentException("image can not be null"); } ArrayList barcodes = new ArrayList(); int iScans = 100; BarcodeImaging.UseBarcodeZones = false; BarcodeImaging.FullScanBarcodeTypes = BarcodeImaging.BarcodeType.Code39; BarcodeImaging.FullScanPage(ref barcodes, image, iScans); return(barcodes); }
private void btnScanCSharp_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK && (!String.IsNullOrEmpty(openFileDialog1.FileName))) { pictureBox1.Image = Bitmap.FromFile(openFileDialog1.FileName); List <string> barCodes = BarcodeImaging.FullScanPage(new Bitmap(Bitmap.FromFile(openFileDialog1.FileName)), 100); StringWriter message = new StringWriter(); foreach (String code in barCodes) { message.WriteLine(code); } MessageBox.Show(message.ToString()); } }
private void btnScan_Click(object sender, EventArgs e) { System.Collections.ArrayList BarcodesScanned = new System.Collections.ArrayList(); if (bmp == null) { MessageBox.Show("Click on the picture box on the left to load an image"); } else { BarcodeImaging.FullScanPage(ref BarcodesScanned, bmp, Convert.ToInt32(txtNumberScans.Text)); if (BarcodesScanned.Count == 0) { MessageBox.Show("No Barcodes found"); } else { lstBarcodes.DataSource = BarcodesScanned; } } }
private void btnScan_Click(object sender, EventArgs e) { string curr_dir = Directory.GetCurrentDirectory(); OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "PDF Files (*.pdf)|*.pdf|TIFF Files (*.tif)|*.tif|JPEG Files (*.jpg)|*.jpg|PNG Files (*.png)|*.png|All Files (*.*)|*.*"; DialogResult result = dlg.ShowDialog(); string filename = ""; if (result == DialogResult.OK) { filename = dlg.FileName; } Directory.SetCurrentDirectory(curr_dir); if (Path.GetExtension(filename).ToLower() == ".pdf") { filename = ConvertPdf2Img(filename); } //Console.Write(filename); if (!File.Exists(filename)) { MessageBox.Show(string.Format("Could not file the image file {0}", filename)); return; } picBox.Image = Image.FromFile(filename); System.Collections.ArrayList barcodes = new System.Collections.ArrayList(); DateTime dtStart = DateTime.Now; int iScans = 100; BarcodeImaging.FullScanPage(ref barcodes, (Bitmap)picBox.Image, iScans); ShowResults(dtStart, iScans, barcodes); }
static void DetectFrequency() { camera = new xiCam(); try { int cameraCount = camera.GetNumberDevices(); camera.OpenDevice(cameraCount - 1); //camera.SetParam(PRM.BUFFER_POLICY, BUFF_POLICY.SAFE); // Set device exposure to 2 milliseconds(2000 microseconds(us)) int exposure_us = 2000; exposure_us = 1975; //exposure_us = 800;//50;//150;//200; //exposure_us = 11;//291;//369; camera.SetParam(PRM.EXPOSURE, exposure_us); // Set device gain to 5 decibels float gain_db = 5; //gain_db = 30; //gain_db = 28.7f;//28.3f; camera.SetParam(PRM.GAIN, gain_db); // Set image output format to monochrome 8 bit camera.SetParam(PRM.IMAGE_DATA_FORMAT, IMG_FORMAT.MONO8); //camera.SetParam(PRM.IMAGE_DATA_FORMAT, IMG_FORMAT.RAW8); //camera.SetParam(PRM.AEAG, 1); ////camera.SetParam(PRM.EXPOSURE_MAX, 200); //camera.SetParam(PRM.EXPOSURE_MAX, 1); ////camera.SetParam(PRM.GAIN_MAX, 16); //camera.SetParam(PRM.GAIN_MAX, 25); //camera.SetParam(PRM.AEAG_LEVEL, 40); camera.StartAcquisition(); Console.WriteLine(camera.GetParamString(xiApi.NET.PRM.DEVICE_NAME)); Console.WriteLine(camera.GetParamString(xiApi.NET.PRM.DEVICE_SN)); string command = "y"; //string defaultBufferSize = camera.GetParamString(PRM.ACQ_BUFFER_SIZE); //int bufferSize = 53248000;//int.Parse(defaultBufferSize); //byte[] imageBytes = new byte[bufferSize]; //MemoryStream stream; FileStream fileStream; Bitmap bitmap = null; System.Collections.ArrayList barcodes = new System.Collections.ArrayList(); int scanningTimes = 75; //Image image; while (command.ToLower() == "y") { //camera.GetImage(imageBytes, 5000); //stream = new MemoryStream(); //stream.Write(imageBytes, 0, imageBytes.Length); //image = Image.FromStream(stream); //bitmap = new Bitmap(image); camera.GetImage(out bitmap, 5000); //bitmap = BarcodeImaging.RotateImage(bitmap, 1); barcodes = new System.Collections.ArrayList(); BarcodeImaging.FullScanPage(ref barcodes, bitmap, scanningTimes); //if ((barcodes != null) && (barcodes.Count > 0)) { Console.WriteLine(DateTime.Now); for (int i = 0; i < barcodes.Count; i++) { Console.WriteLine(barcodes[i]); } string filePath = String.Format("d:\\ximeaCameraTest\\{0}", DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss")); //string filePath = String.Format("d:\\ximeaCameraTest\\{0}", DateTime.Now.ToString("yyyy-MM-dd")); Directory.CreateDirectory(filePath); fileStream = new FileStream(String.Format("{0}\\{1}.bmp", filePath, Guid.NewGuid().ToString()), FileMode.Create, FileAccess.Write, FileShare.Write); bitmap.Save(fileStream, System.Drawing.Imaging.ImageFormat.Bmp); fileStream.Flush(); fileStream.Close(); } //Console.WriteLine("Continue? (Y/N)"); //command = Console.ReadLine(); } camera.StopAcquisition(); camera.CloseDevice(); Console.WriteLine("Press any key to exit..."); Console.Read(); } catch (Exception ex) { camera.CloseDevice(); Console.WriteLine(ex.ToString()); Console.Read(); } finally { camera.CloseDevice(); } }
private void ReadBarcode(string sFromFilePath) { string sFromPath = txtFrom.Text; string sFileName = sFromFilePath.Replace((sFromPath + "\\"), ""); System.Drawing.Bitmap oImage = null; try { oImage = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile(sFromFilePath); } catch (Exception ex) { if (chkLog.Checked) { txtOutput.AppendText((sFileName + ('\t' + ("Could not open" + "\r\n")))); } this.WriteLog((sFileName + ("," + "Could not open"))); return; } System.Collections.ArrayList barcodes = new System.Collections.ArrayList(); int iScans = 100; DateTime dtStart = DateTime.Now; BarcodeImaging.UseBarcodeZones = chkUseBarcodeZones.Checked; BarcodeImaging.BarcodeType oBarcodeType = BarcodeImaging.BarcodeType.All; switch (cbBarcodeType.Text) { case "Code39": oBarcodeType = BarcodeImaging.BarcodeType.Code39; break; case "Code128": oBarcodeType = BarcodeImaging.BarcodeType.Code128; break; case "EAN": oBarcodeType = BarcodeImaging.BarcodeType.EAN; break; } switch (cbDirection.Text) { case "All": BarcodeImaging.FullScanBarcodeTypes = oBarcodeType; BarcodeImaging.FullScanPage(ref barcodes, oImage, iScans); break; case "Vertical": BarcodeImaging.ScanPage(ref barcodes, oImage, iScans, BarcodeImaging.ScanDirection.Horizontal, oBarcodeType); break; case "Horizontal": BarcodeImaging.ScanPage(ref barcodes, oImage, iScans, BarcodeImaging.ScanDirection.Vertical, oBarcodeType); break; } string sSec = ""; if (chkShowTime.Checked) { sSec = ('\t' + DateTime.Now.Subtract(dtStart).TotalSeconds.ToString("#0.00")); } if ((barcodes.Count == 0)) { if (chkLog.Checked) { txtOutput.AppendText((sFileName + ('\t' + ("Failed" + (sSec + "\r\n"))))); } this.WriteLog((sFileName + ("," + "Failed"))); } else { foreach (object bc in barcodes) { if (chkLog.Checked) { txtOutput.AppendText((sFileName + ('\t' + (bc + (sSec + "\r\n"))))); } this.WriteLog((sFileName + ("," + bc))); } } oImage.Dispose(); }
private void btnScanAll_Click(object sender, EventArgs e) { using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang đổi tên file trong thư mục Scan")) { for (int i = 0; i < grvScan.RowCount; i++) { try { string filePath = grvScan.GetRowCellValue(i, colFilePath).ToString(); string thisProductCode = ""; if (Path.GetExtension(filePath) == ".jpg") { Image img = Image.FromFile(filePath); Bitmap mBitmap = new Bitmap(img); ArrayList barcodes = new ArrayList(); BarcodeImaging.FullScanPage(ref barcodes, mBitmap, 100); //string[] barcodes = BarcodeReader.read(mBitmap, BarcodeReader.CODE39); mBitmap.Dispose(); string contentBarcode = barcodes.ToArray().Where(o => o.ToString().StartsWith("+")).ToArray()[0].ToString();//nội dung barcode chứa tên biểu mẫu (VD: 2.BM01.A0101) thisProductCode = "TPAD." + contentBarcode.Substring(3); if (!thisProductCode.ToUpper().Contains(_productCode)) { continue; } string destFileName = @"D:\Thietke.Ck\TPAD." + _productCode.Substring(5, 1) + "\\" + _productCode + ".Ck\\BCCk." + _productCode + "\\BC-CAD." + _productCode + "\\" + thisProductCode + ".jpg"; if (File.Exists(destFileName)) { DialogResult result = MessageBox.Show("Đã tồn tại file: '" + thisProductCode + ".jpg' trong thiết kế" + Environment.NewLine + "Bạn có muốn ghi đè lên file cũ không?", TextUtils.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { File.Delete(destFileName); File.Copy(filePath, destFileName, true); img.Dispose(); mBitmap.Dispose(); File.Delete(filePath); } else { TextUtils.RenameFileVB(filePath, thisProductCode + ".jpg"); } } else { File.Copy(filePath, destFileName, true); img.Dispose(); mBitmap.Dispose(); File.Delete(filePath); } } else if (Path.GetExtension(filePath).ToLower() == ".pdf") { System.Collections.ArrayList barcodes = new System.Collections.ArrayList(); string outputFilePath = Path.GetDirectoryName(filePath) + "\\" + Path.GetFileNameWithoutExtension(filePath) + ".png"; pdfConverter().Convert(filePath, outputFilePath); Bitmap mBitmap = new Bitmap(outputFilePath); BarcodeImaging.FullScanPage(ref barcodes, mBitmap, 100); //string[] barcodes = BarcodeReader.read(mBitmap, BarcodeReader.CODE39); mBitmap.Dispose(); File.Delete(outputFilePath); string contentBarcode = barcodes.ToArray().Where(o => o.ToString().StartsWith("2.")).ToArray()[0].ToString();//nội dung barcode chứa tên biểu mẫu (VD: 2.BM01.A0101) string templateCode = contentBarcode.Split('.')[1]; TemplateModel temModel = (TemplateModel)TemplateBO.Instance.FindByAttribute("Code", templateCode)[0]; int tempType = temModel.Type; string code = contentBarcode.Split('.')[2]; if (tempType == 1 || tempType == 2) //1:cơ khí,2:điện,3:điện tử { thisProductCode = "TPAD." + code; } else { thisProductCode = "PCB." + code; } if (_productCode != thisProductCode) { continue; } string tempName = temModel.Name.Replace("code", thisProductCode); string tempFolderPath = temModel.PathFolderC.Replace("code", thisProductCode); if (tempType == 1) { string destFileName = @"D:\Thietke.Ck\TPAD." + code.Substring(0, 1) + "\\" + tempFolderPath + "\\" + tempName + Path.GetExtension(filePath); checkBeforeCopyFile(filePath, destFileName); } if (tempType == 2) { } if (tempType == 3) { string destFileName = @"D:\Thietke.Dt\PCB." + code.Substring(0, 1) + "\\" + tempFolderPath + "\\" + tempName + ".pdf"; checkBeforeCopyFile(filePath, destFileName); } } } catch (Exception) { continue; } } btnRefresh_Click(null, null); } }
private void btnRotate_Click(object sender, EventArgs e) { bmp = BarcodeImaging.RotateImage(bmp, (float)Convert.ToDouble(txtDegrees.Text)); pbImageToScan.Image = bmp; }