private void btnCreatebarcode_Click(object sender, EventArgs e) { this.barCodeControl1.TopText = "\n" + txtcompany.Text + "\n ================= \n" + txttoptext.Text + "\n\nPrice: " + txtCurrency.Text + txtPrice.Text; this.barCodeControl1.SupSpace = 22; //generate the barcode use the settings BarCodeGenerator generator = new BarCodeGenerator(barCodeControl1); Image barcode = generator.GenerateImage(); this.barCodeControl1.SaveToFile("barcodeImage.png"); btnSaveimage.Enabled = true; string barcodeimagestore = Application.StartupPath + @"\barcodeImage.png"; //save the barcode as an image // barcode.Save(@"..\..\..\BarCode\barcode.png"); // barcode.Save(barcodeimagestore); //launch the generated barcode image // string path = "..\\..\\..\\BarCode\\barcode.png"; picbarcode1.ImageLocation = barcodeimagestore; picbarcode2.ImageLocation = barcodeimagestore; picbarcode3.ImageLocation = barcodeimagestore; picbarcode4.ImageLocation = barcodeimagestore; picbarcode5.ImageLocation = barcodeimagestore; picbarcode6.ImageLocation = barcodeimagestore; }
private void btnTicketPrint_Click(object sender, EventArgs e) { try { BarcodeSettings barsetting = new BarcodeSettings(); //set the x dimension barsetting.X = 0.8f; barsetting.Unit = GraphicsUnit.Millimeter; barsetting.HasBorder = true; barsetting.BorderWidth = 0.5F; //set the data barsetting.Data = tbUserId.Text; barsetting.Data2D = tbUserId.Text; //generate EAN128 barcode barsetting.Type = BarCodeType.Code128; BarCodeGenerator bargenerator = new BarCodeGenerator(barsetting); Image barcodeimage = bargenerator.GenerateImage(); filename = "C:/xampp/htdocs/ProP_Sems2/Applications/C#/Main GUI/HHF APP/bin/Debug/barcodes" + tbUserId.Text + ".png"; barcodeimage.Save(filename); PrintDocument pd = new PrintDocument(); pd.PrintPage += PrintPage; pd.Print(); Process.Start(filename); // Process.Start(@filename); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private object Get2DBarcode(DataRow row) { string data = ParseData(string.Format("HRVHUB30\nHRK\n{0}\n{1}\n{2}\n{3}\n{4}\n{5}\n{6}\n{7}\nHR{8}\n{9}\nOTHR\n{10}\n", GetCijenaBarcode(row["UkupanIznos"]), row["RoditeljIme"].ToString() + " " + row["RoditeljPrezime"].ToString(), row["adresa"], row["grad"], row["ustanovaNaziv"], row["ustanovaAdresa"], row["ustanovaPosta"].ToString() + " " + row["ustanovaGrad"].ToString(), row["ustanoaIBAN"].ToString().Replace(" ", string.Empty), row["ustanovaModel"], row["ustanovaPozivNaBroj"], row["nazivObracuna"])); IBarcodeSettings settings = new BarcodeSettings(); settings.Data = data; settings.Data2D = data; settings.Type = BarCodeType.Pdf417; settings.Pdf417DataMode = Pdf417DataMode.Byte; settings.ShowText = false; settings.ShowTextOnBottom = false; settings.ShowTopText = false; settings.Pdf417Truncated = false; settings.Unit = GraphicsUnit.Millimeter; settings.Pdf417ECL = Pdf417ECL.Level4; settings.ColumnCount = 9; settings.XYRatio = 2.2F; settings.X = 0.5F; settings.Y = 1.0F; BarCodeGenerator gen = new BarCodeGenerator(settings); ImageConverter converter = new ImageConverter(); return((byte[])converter.ConvertTo(gen.GenerateImage(), typeof(byte[]))); }
public static string Generate_Code128(string value) { BarCodeGenerator generator = new BarCodeGenerator(new BarcodeSettings() { Data = value, Type = BarCodeType.Code128, Data2D = value, ShowText = false, TopText = value, BarHeight = 15 }); try { Image barcode = generator.GenerateImage(); Image cropped = CropAtRect(barcode, new Rectangle() { Height = 60, Width = barcode.Width, X = 0, Y = 0, Location = new Point() { X = 0, Y = 17 } }); //I will crop at frontend (so, using barcode instead of cropped) return(Convert.ToBase64String(ConvertBitMapToByteArray(barcode))); } catch (Exception e) { return(""); } }
public static BitmapImage GenerateBarCodeRetBitMap(this string data, bool save = false, string path = "") { BarcodeSettings setting = new BarcodeSettings(); setting.Data = data; //setting.Type = Spire.Barcode.BarCodeType.Code93Extended; BarCodeGenerator gen = new BarCodeGenerator(setting); Image barcodeimage = gen.GenerateImage(); if (save) { if (File.Exists(path + "\\" + data + ".png")) { // File.Delete(path + "\\" + data + ".png"); } barcodeimage.Save(path + "\\" + data + ".png", ImageFormat.Png); } MemoryStream ms = new MemoryStream(); //variable that holds image barcodeimage.Save(ms, ImageFormat.Bmp); //my buffer byte byte[] buffer = ms.GetBuffer(); //Create new MemoryStream that has the contents of buffer MemoryStream bufferPasser = new MemoryStream(buffer); BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.StreamSource = bufferPasser; bitmap.EndInit(); return(bitmap); }
public static Image GenerateBarCode(this string data, bool save = false, string path = "") { BarcodeSettings setting = new BarcodeSettings(); setting.Data = data; setting.Type = Spire.Barcode.BarCodeType.Code93Extended; BarCodeGenerator gen = new BarCodeGenerator(setting); Image barcodeimage = gen.GenerateImage(); if (save) { if (!Directory.Exists(path)) { AdminstrationHelper.MakeDirectory(path); } if (File.Exists(path + "\\" + data + ".png")) { // File.Delete(path + "\\" + data + ".png"); } barcodeimage.Save(path + "\\" + data + ".png", ImageFormat.Png); } return(barcodeimage); }
private void generateBarCode_ButtonClick(object sender, EventArgs e) { string barCode = textBox1.Text.Trim(); try { if (!codeLength(barCode)) { throw new Exception(); } BarcodeSettings barcodeSettings = new BarcodeSettings(); barcodeSettings.Type = BarCodeType.EAN13; barcodeSettings.Data = barCode; barcodeSettings.UseChecksum = CheckSumMode.ForceEnable; barcodeSettings.ShowTextOnBottom = true; barcodeSettings.TextAlignment = StringAlignment.Center; BarCodeGenerator generator = new BarCodeGenerator(barcodeSettings); Image barCodeImage = generator.GenerateImage(); barCodeImage = usunNapis(barCodeImage); pictureBox1.Image = barCodeImage; } catch (Exception ex) { MessageBox.Show("Podano kod o zlej dlugosci"); } }
// Esse plugin usa o NuGET Spire.Barcode public Image SalvarCodigoBarras(string mensagem, string arquivo = null) { // Configura Codigo de Barras BarcodeSettings config = new BarcodeSettings(); config.ShowText = false; config.ShowTopText = false; config.ShowCheckSumChar = false; config.ShowTextOnBottom = false; config.ShowStartCharAndStopChar = false; // Atribui valor ao Codigo de Barras config.Data = mensagem; // Gera o Codigo de Barras BarCodeGenerator barcode = new BarCodeGenerator(config); Image code = barcode.GenerateImage(); // Salva Imagem if (!string.IsNullOrEmpty(arquivo)) { code.Save(arquivo.Replace(".png", "") + ".png", ImageFormat.Png); } // Retorna Imagem Codigo de Barras return(code); }
private void Get_AWS_Data_Click(object sender, RoutedEventArgs e) { string ID_Code = ""; string Key_return = ""; Communication_DatabaseEntities1 var_data = new Communication_DatabaseEntities1(); var Key_Return = var_data.Register_User(First_Name_Input.Text, Last_Name_Input.Text); foreach (var item in Key_Return) { Console.WriteLine(item.Pass_Key); Console.WriteLine(item.User_ID); ID_Code = item.User_ID.ToString(); Key_return = item.Pass_Key; } string QR_INPUT = ID_Code + "," + Key_return; BarcodeSettings bs = new BarcodeSettings(); bs.Type = BarCodeType.QRCode; bs.Data = QR_INPUT; BarCodeGenerator bg = new BarCodeGenerator(bs); bg.GenerateImage().Save("QRCode.png"); System.Diagnostics.Process.Start("QRCode.png"); MessageBox.Show("User Added!"); Outside_User enter_pass = new Outside_User(); enter_pass.Show(); }
public static void Generate(string barcode) { var settings = new BarcodeSettings { Type = BarCodeType.EAN128, Data = barcode, ShowTextOnBottom = true, TextAlignment = StringAlignment.Center }; var generator = new BarCodeGenerator(settings); Image barcodeImage = generator.GenerateImage(); string path = HttpRuntime.AppDomainAppPath.ToString() + "Images\\Barcode\\"; using (Bitmap bitmap = new Bitmap(barcodeImage)) { //string wantPath = Server.MapPath("~/Images/Barcode/"); if (!Directory.Exists(path)) { //如果不存在就创建 Directory.CreateDirectory(path); bitmap.Save(path + barcode + ".jpg"); } else { bitmap.Save(path + barcode + ".jpg"); } } //MyBarcodeGenerator.ShowBarcode(book.isbn13, this.Response); //return barcodeImage; }
private void Frmcode_Load(object sender, EventArgs e) { label1.Text = Form3.NO_code; BarcodeSettings.ApplyKey("your key");//you need a key from e-iceblue, otherwise the watermark 'E-iceblue' will be shown in barcode BarcodeSettings settings = new BarcodeSettings(); settings.Type = BarCodeType.QRCode; settings.Unit = GraphicsUnit.Pixel; settings.ShowText = false; settings.ResolutionType = ResolutionType.UseDpi; //input data string data = label1.Text; settings.Data = data; settings.X = 6; settings.ForeColor = Color.Blue; //generate QR code BarCodeGenerator generator = new BarCodeGenerator(settings); Image QRbarcode = generator.GenerateImage(); //display QR code image in picture box pictureBox1.Image = QRbarcode; }
public void TestInvalidImage() { BarCodeGenerator generator = MakeInvalidGenerator(); Assert.Throws <BarCodeFormatException>(() => { using (generator.GenerateImage()) { } }); }
public void GuardaCodigoBarras() { string rutaYNomArchivo = _rutaXml.Trim() + "cbb\\" + _nomArchivo + ".png"; sMsj = ""; iErr = 0; try { //Genera y guarda código de barras bidimensional BarcodeSettings settings = new BarcodeSettings(); settings.Pdf417DataMode = Pdf417DataMode.Byte; settings.Pdf417Truncated = false; settings.Pdf417ECL = Pdf417ECL.Level5; settings.DpiX = 100; settings.DpiY = 100; settings.ImageHeight = 1; settings.ImageWidth = 3; settings.XYRatio = 3; settings.Data2D = _modeloDte.modeloTed.xDocXml.OuterXml; settings.Data = _modeloDte.modeloTed.xDocXml.OuterXml; settings.Type = (BarCodeType)Enum.Parse(typeof(BarCodeType), "Pdf417"); settings.ShowText = false; settings.BarHeight = 15; settings.ShowCheckSumChar = true; settings.ForeColor = Color.FromName("Black"); //generate the barcode use the settings BarCodeGenerator generator = new BarCodeGenerator(settings); Image barcode = generator.GenerateImage(); //save the barcode as an image barcode.Save(rutaYNomArchivo); } catch (DirectoryNotFoundException) { sMsj = "Verifique la existencia de la ruta indicada en la configuración de Ruta de archivos Xml. No existe la ruta actual: " + _rutaXml.Trim() + " [CFDComprobanteFiscalDigital.GuardaCodigoBarras]"; iErr++; } catch (IOException) { sMsj = "Verifique permisos de escritura en: " + _rutaXml.Trim() + ". No se pudo guardar el código de barras. [CFDComprobanteFiscalDigital.GuardaCodigoBarras]"; iErr++; } catch (Exception eAFE) { if (eAFE.Message.Contains("denied")) { sMsj = "Elimine el archivo xml, luego vuelva a intentar. " + eAFE.Message + " [CFDComprobanteFiscalDigital.GuardaCodigoBarras]"; } else { sMsj = "No se puede guardar el código de barras. " + eAFE.Message + " [CFDComprobanteFiscalDigital.GuardaCodigoBarras] " + eAFE.StackTrace; } iErr++; } }
private void button1_Click(object sender, EventArgs e) { BarcodeSettings bs = new BarcodeSettings(); bs.Type = BarCodeType.PZN; bs.Data = "12345"; BarCodeGenerator bg = new BarCodeGenerator(bs); bg.GenerateImage().Save("PZNCode.png"); System.Diagnostics.Process.Start("PZNCode.png"); }
public FrayteResult CreateWarehouseLocation(string LocationName, string countryCode) { FrayteResult result = new FrayteResult(); Location location = new Location(); location.WarehouseId = 1; location.LocationName = LocationName; location.CountryId = 228; dbContext.Locations.Add(location); dbContext.SaveChanges(); location.Barcode = CommonConversion.GetNewFrayteNumber() + "|" + countryCode + "|" + location.LocationId; dbContext.SaveChanges(); BarcodeSettings settings = new BarcodeSettings(); string data = location.Barcode; string type = "Code128"; short fontSize = 8; string font = "SimSun"; settings.Data2D = data; settings.Data = data; settings.Type = (BarCodeType)Enum.Parse(typeof(BarCodeType), type); if (fontSize != 0 && fontSize.ToString().Length > 0 && Int16.TryParse(fontSize.ToString(), out fontSize)) { if (font != null && font.Length > 0) { settings.TextFont = new System.Drawing.Font(font, fontSize, FontStyle.Bold); } } short barHeight = 15; if (barHeight != 0 && barHeight.ToString().Length > 0 && Int16.TryParse(barHeight.ToString(), out barHeight)) { settings.BarHeight = barHeight; } BarCodeGenerator generator = new BarCodeGenerator(settings); Image barcode = generator.GenerateImage(); // Path where we will have barcode string filePathToSave = AppSettings.LabelFolder + "Waerehouse/"; filePathToSave = HttpContext.Current.Server.MapPath(filePathToSave + location.LocationId); if (!System.IO.Directory.Exists(filePathToSave)) { System.IO.Directory.CreateDirectory(filePathToSave); } barcode.Save(filePathToSave + "/" + location.LocationName + ".Png"); result.Status = true; return(result); }
private void button1_Click(object sender, EventArgs e) { BarcodeSettings bs = new BarcodeSettings(); bs.Type = BarCodeType.RSSExpanded; bs.Data = "(12)345678(90)"; BarCodeGenerator bg = new BarCodeGenerator(bs); bg.GenerateImage().Save("RSSExpandedCode.png"); System.Diagnostics.Process.Start("RSSExpandedCode.png"); }
public void TestValidImage() { BarCodeSettings settings = SettingsUtils.CreateTestSettings(); BarCodeGenerator generator = new BarCodeGenerator(settings); using (var image = generator.GenerateImage()) { AssertImage(image); Assert.AreEqual(settings.Dpi, image.HorizontalResolution); Assert.AreEqual(settings.Dpi, image.VerticalResolution); } }
private void tSBSaveBarcode_Click(object sender, EventArgs e) { BarCodeGenerator bcg = new BarCodeGenerator(bs); SaveFileDialog sf = new SaveFileDialog(); sf.Filter = "Bitmap Image(*.bmp)|*.bmp|JPEG Image(*.jpg)|*.jpg|PNG Image(*.png)|*.png"; if (sf.ShowDialog() == DialogResult.OK) { bcg.GenerateImage().Save(sf.FileName); } }
/// <summary> /// Asserts the valid generation of a barcode image. /// </summary> /// <param name="type">The barcode type to render.</param> /// <param name="data">The data to render.</param> private void AssertBarcode(BarCodeType type, string data) { BarCodeSettings settings = new BarCodeSettings(); settings.Type = type; settings.Data = data; BarCodeGenerator generator = new BarCodeGenerator(settings); using (var image = generator.GenerateImage()) { AssertImage(image); } }
// Methods /// Constructor public Code() { // Resizes the window HeadWars.Resize(320, 300); labels.Add(new HLabel(Translation.GetString("secret_code"), Font.WindowTitle)); labels[0].setPosition(0, 0, "xcenter top"); // Code textboxes.Add(new HTextBox(0, 0, 17, false, 250, 45)); textboxes[0].setFont(Font.MediumTextBold); textboxes[0].setPosition(0, 40, "xcenter ycenter"); buttons.Add(new HButton(Translation.GetString("validate"), 0, 0)); buttons[0].setPosition(0, 90, "xcenter ycenter"); labels.Add(new HLabel(message = "", Font.Text)); labels[1].setPosition(0, 140, "xcenter"); buttons.Add(new HButton(Translation.GetString("button_back"), 0, 0)); buttons[1].setPosition(0, 0, "left bottom"); // QR Code DatabaseManager.Connect(); string data = DatabaseManager.getCode(); DatabaseManager.Disconnect(); if (data == null) { QRCodeTexture = Graphic.no_code; } else { BarcodeSettings settings = new BarcodeSettings { Unit = GraphicsUnit.Pixel, Type = BarCodeType.QRCode, ResolutionType = ResolutionType.UseDpi, BackColor = System.Drawing.Color.White, ForeColor = System.Drawing.Color.Black, X = 4, Data = data, DpiY = 1, DpiX = 1 }; BarCodeGenerator generator = new BarCodeGenerator(settings); QRCodeTexture = bitmapToTexture2D((Bitmap)generator.GenerateImage()); } QrCodeRectangle = new Microsoft.Xna.Framework.Rectangle(0, 0, QRCodeTexture.Width, QRCodeTexture.Height); }
private void btnGenerate_Click(object sender, EventArgs e) { BarCodeGenerator BCG = new BarCodeGenerator(bs); try { this.pictureBox1.Image = BCG.GenerateImage(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private string SaveToFile(BarCodeSettings settings) { BarCodeGenerator generator = new BarCodeGenerator(settings); var dirName = Path.Combine(Path.GetTempPath(), "barcodes"); Directory.CreateDirectory(dirName); using (var image = generator.GenerateImage()) { var fileName = string.Format("{0}_{1}_{2}.png", settings.Type, settings.Dpi, MakeValidFileName(settings.Data)); var filePath = Path.Combine(dirName, fileName); Trace.WriteLine(string.Format("Saving barcode image: {0}", filePath)); image.Save(filePath, System.Drawing.Imaging.ImageFormat.Png); return(filePath); } }
private void btnImprimir_Click(object sender, EventArgs e) { if (codBarrasProductoSeleccionado.Length != 12) { MessageBox.Show("Debe seleccionarse un producto antes de poder imprimir su código de barras.", "ATENCIÓN", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { String codigoBarras = codBarrasProductoSeleccionado + Util.SacarControl(ulong.Parse(codBarrasProductoSeleccionado)); BarcodeSettings settings = new BarcodeSettings(); settings.Type = BarCodeType.EAN13; settings.Data = codigoBarras.ToString(); settings.ResolutionType = ResolutionType.Graphics; BarCodeGenerator generator = new BarCodeGenerator(settings); Image image = generator.GenerateImage(); image.RotateFlip(RotateFlipType.Rotate180FlipX); Bitmap b = Util.CropImage(image, new Rectangle(0, 0, image.Width, image.Height - 30)); b.RotateFlip(RotateFlipType.Rotate180FlipX); PrintDocument pd = new PrintDocument(); pd.PrinterSettings.PrinterName = "Brother QL-700"; pd.DefaultPageSettings.Landscape = false; var sizes = pd.PrinterSettings.PaperSizes; PaperSize ps = null; foreach (PaperSize s in sizes) { if (s.PaperName.Equals("62mm x 29mm")) { ps = s; break; } } pd.DefaultPageSettings.PaperSize = ps; pd.PrintPage += (s, args) => { args.Graphics.DrawString(productoExistenteSeleccionado != null ? productoExistenteSeleccionado.Descripcion : txtDescripcion.Text, new Font("Arial", 8), new SolidBrush(Color.Black), 0, 0); args.Graphics.DrawString(productoExistenteSeleccionado != null ? productoExistenteSeleccionado.Coste.ToString() + "€" : nudCoste.Value.ToString() + "€", new Font("Arial", 8), new SolidBrush(Color.Black), 0, 10); args.Graphics.DrawImage(b, new Rectangle(0, 22, b.Width, b.Height)); }; PrintDialog pdi = new PrintDialog(); pdi.Document = pd; if (pdi.ShowDialog() == DialogResult.OK) { pd.Print(); } } }
public static Bitmap GenerateQRCode(string data) { string filename = rand.Next().ToString() + ".png"; BarcodeSettings settings = new BarcodeSettings(); settings.Type = BarCodeType.QRCode; settings.Data = data; settings.X = 1.0f; settings.QRCodeECL = QRCodeECL.H; BarCodeGenerator generator = new BarCodeGenerator(settings); Image image = generator.GenerateImage(); return(new Bitmap(image)); }
public static Image Generate(string strcontent) { BarcodeSettings settings=new BarcodeSettings(); settings.BarHeight = 15; settings.Data = strcontent; settings.Data2D = strcontent; settings.Type = BarCodeType.Pdf417; settings.X =6; settings.ShowText = false; settings.ShowTextOnBottom = false; settings.ShowCheckSumChar = false; BarCodeGenerator generator = new BarCodeGenerator(settings); Image barcode = generator.GenerateImage(); return barcode; }
private System.Drawing.Image BarCodeImage() { BarcodeSettings setting = new BarcodeSettings { Type = BarCodeType.Code39, Unit = GraphicsUnit.Millimeter, X = 0.4F, Data = ticket_id.ToString(), ShowText = false }; BarCodeGenerator generator = new BarCodeGenerator(setting); return(generator.GenerateImage()); }
public void BarCodeGenerationRaw(BarCodeTestInput input) { int dpi = 120; BarCodeGenerator generator = new BarCodeGenerator(new BarCodeSettings { Type = input.Type, Data = input.Data, Dpi = dpi }); var dirName = Path.Combine(Path.GetTempPath(), "barcodes"); Directory.CreateDirectory(dirName); using (var image = generator.GenerateImage()) { var filePath = string.Format("{0}\\{1}_{2}_{3}.png", dirName, input.Type, dpi, MakeValidFileName(input.Data)); Trace.WriteLine(string.Format("Saving barcode image: {0}", filePath)); image.Save(filePath, System.Drawing.Imaging.ImageFormat.Png); } }
/// <summary> /// Draws the barcode in the canvas passed. /// </summary> /// <param name="canvas">Canvas to draw barcode into.</param> public void DrawBarCode(Graphics canvas) { string errorMessage; if (_generator.TestRender(out errorMessage)) { using (var barCodeImage = _generator.GenerateImage()) { Size = new Size(barCodeImage.Width, barCodeImage.Height); canvas.DrawImage(barCodeImage, 0, 0); } } else { Size = new Size(250, 50); canvas.DrawString(errorMessage, _errorFont, _errorBrush, new RectangleF(0, 0, 250, 50)); } }
public static Image Generate(string strcontent) { BarcodeSettings settings = new BarcodeSettings(); settings.BarHeight = 15; settings.Data = strcontent; settings.Data2D = strcontent; settings.Type = BarCodeType.Pdf417; settings.X = 6; settings.ShowText = false; settings.ShowTextOnBottom = false; settings.ShowCheckSumChar = false; BarCodeGenerator generator = new BarCodeGenerator(settings); Image barcode = generator.GenerateImage(); return(barcode); }
public string GenerateQRCode(string content) { Image QRbarcode; BarcodeSettings.ApplyKey("DAAA84F486628A6DE4160D9E7465D733"); BarcodeSettings settings = new BarcodeSettings(); settings.Type = BarCodeType.QRCode; settings.Unit = GraphicsUnit.Pixel; settings.ShowText = false; settings.ResolutionType = ResolutionType.UseDpi; //input data settings.Data = content; //set fore color settings.ForeColor = Color.FromName("Black"); //set back color settings.BackColor = Color.FromName("White"); //set x settings.X = 10; //set left margin settings.LeftMargin = 1; //set right margin settings.RightMargin = 1; //set top margin settings.TopMargin = 1; //set bottom margin settings.BottomMargin = 1; //set correction level settings.QRCodeECL = QRCodeECL.L; //generate QR code BarCodeGenerator generator = new BarCodeGenerator(settings); QRbarcode = generator.GenerateImage(); //return QRbarcode; return(ImageToBase64(QRbarcode)); }
public void BarCodeGenerationTest(BarCodeTestInput input) { Trace.WriteLine(string.Format("Testing: {0}, {1}", input.Type, input.Data)); BarCodeGenerator generator = new BarCodeGenerator(new BarCodeSettings { Type = input.Type, Data = input.Data }); using (var image = generator.GenerateImage()) { // "recognize" the barcode var reader = CreateReader(input.Reader); var result = reader.ReadBarCode((Bitmap)image); Assert.AreEqual(input.Type, result.Type, "Type of barcode differs!"); Assert.AreEqual(input.Expected, result.Data, "Barcode data differs!"); } }
private byte[] getBarcodeImage(string barcode, string title) { byte[] retval = null; try { BarcodeSettings settings = new BarcodeSettings(); settings.Type = (BarCodeType)Enum.Parse(typeof(BarCodeType), "Code128"); settings.Data = barcode; settings.HasBorder = false; settings.TextFont = new System.Drawing.Font("SimSun", 8, FontStyle.Bold); settings.BarHeight = 15; settings.ShowText = true; settings.ShowCheckSumChar = false; settings.ForeColor = Color.FromName("Black"); BarCodeGenerator generator = new BarCodeGenerator(settings); Image barcodeImg = generator.GenerateImage(); using (var ms = new MemoryStream()) { barcodeImg.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); retval = ms.ToArray(); } } catch (Exception e) { throw; } return retval; //try //{ // BarCode39 _barcode = new BarCode39(); // int barSize = 128; // string fontFile = System.Web.HttpContext.Current.Server.MapPath("~/fonts/FREE3OF9.TTF"); // return (_barcode.Code39(barcode, barSize, true, title, fontFile)); //} //catch (Exception ex) //{ // //ErrorLog.WriteErrorLog("Barcode", ex.ToString(), ex.Message); //} }