private void Form1_Load(object sender, EventArgs e) { //Create a DataSet from the XML file string filePath = "..\\..\\Employees.xml"; DataSet ds = new DataSet(); ds.ReadXml(filePath); //Create and add barcode column DataColumn dc = new DataColumn("BarcodeImage", typeof(byte[])); ds.Tables[0].Columns.Add(dc); //We'll use Code 128 Barcode Symbology BaseBarcode b = BarcodeFactory.GetBarcode(Symbology.Code128); b.Height = 50; b.FontHeight = 0.3F; //Now, generate and fill barcode images foreach (DataRow dr in ds.Tables[0].Rows) { //We'll encode the ID column b.Number = (string)dr["ID"]; //Create bitmap and save it to BarcodeImage column MemoryStream ms = new MemoryStream(); b.Save(ms, ImageType.Png); dr["BarcodeImage"] = ms.GetBuffer(); } CrystalReport1 report = new CrystalReport1(); report.SetDataSource(ds); crystalReportViewer1.ReportSource = report; }
private static void WriteBarcodeImageToStream(BaseBarcode b) { HttpContext.Current.Response.ContentType = "image/png"; MemoryStream ms = new MemoryStream(); b.Save(ms, ImageType.Png); WriteMemoryStream(ms); }
private void buttonGenerate_Click(object sender, EventArgs e) { BaseBarcode barcode = BarcodeFactory.GetBarcode(Symbology.EAN13); barcode.Number = tbEan.Text; if (cbControlSum.Checked == true) { barcode.ChecksumAdd = true; } else { barcode.ChecksumAdd = false; } pbBarCode.Image = barcode.Render(); barcode.Save("barcode.png", ImageType.Png); }
private void Generate_Click(object sender, EventArgs e) { BaseBarcode barcode = BarcodeFactory.GetBarcode(Symbology.EAN13); barcode.Number = textBoxEAN.Text; if (checkBoxSumCtrl.Checked) { barcode.ChecksumAdd = true; } else { barcode.ChecksumAdd = false; } pictureBoxBarcode.Image = barcode.Render(); barcode.Save("barcode.png", ImageType.Png); }
static void Main(string[] args) { // Later we will set the resolution to 300 dpi (dots per inch) // 36 PostScript points = 0.5 inches (1.27 cm) BaseBarcode barcode = BarcodeFactory.GetBarcode(Symbology.Code39Ext); barcode.Number = "1234567890"; barcode.NarrowBarWidth = 12; // 12 dots / 300 dpi = 0.04 inch (0.1 cm) barcode.ChecksumAdd = true; barcode.ChecksumVisible = true; barcode.Height = 600; // Barcode image after printing will be 2 inches high (600 dots / 300 dpi) including the text barcode.FontHeight = 0.25f; // font size will be 0.5 inch (1.27 cm) height (2 inch * 0.25) which is 36 PostScript points // here we set the resolution barcode.Save(_fileName, ImageType.Png, 300, 300); Console.WriteLine("Barcode saved to: '{0}'", Path.GetFullPath(_fileName)); Console.ReadKey(true); }