BarcodeDraw drawObject = BarcodeDrawFactory.CodeEan13WithChecksum; //BarcodeDraw drawObject = BarcodeDrawFactory.CodeQr; BarcodeMetrics metrics = drawObject.GetDefaultMetrics(60); metrics.Scale = 2; //text = appendChecksum(text); var barcodeImage = drawObject.Draw("123456789012", metrics); var resultImage = new Bitmap(barcodeImage.Width, barcodeImage.Height + 20); using (var graphics = Graphics.FromImage(resultImage)) using (var font = new Font("Consolas", 12)) // Any font you want using (var brush = new SolidBrush(Color.Black)) using (var format = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Far }) // To align text above the specified point { graphics.Clear(Color.White); // Print a string at the left bottom corner of image graphics.DrawImage(barcodeImage, 0, 0); graphics.DrawString(text, font, brush, resultImage.Width / 2, resultImage.Height, format); } using (MemoryStream ms = new MemoryStream()) { resultImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] imageBytes = ms.ToArray(); return Convert.ToBase64String(imageBytes); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)