Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string font = ConfigurationManager.AppSettings["BarCodeFontFamily"].ToString();
- string barcode = obj[i].barcode;
- if (font != "Code 128")
- {
- using (Bitmap bitMap = new Bitmap(barcode.Length * 40, 100))
- {
- System.Drawing.Font oFont = new System.Drawing.Font(font, 18);
- using (Graphics graphics = Graphics.FromImage(bitMap))
- {
- //System.Drawing.Font oFont = new System.Drawing.Font("IDAutomationHC39M", 18);
- //System.Drawing.Font oFont = new System.Drawing.Font("IDAHC39M Code 39 Barcode", 16);
- PointF point = new PointF(2f, 2f);
- SolidBrush whiteBrush = new SolidBrush(Color.White);
- graphics.FillRectangle(whiteBrush, 0, 0, bitMap.Width, bitMap.Height);
- SolidBrush blackBrush = new SolidBrush(Color.Black);
- graphics.DrawString("*" + barcode + "*", oFont, blackBrush, point);
- }
- using (MemoryStream ms = new MemoryStream())
- {
- bitMap.Save(ms, ImageFormat.Png);
- byte[] byteImage = ms.ToArray();
- Convert.ToBase64String(byteImage);
- image = "data:image/png;base64," + Convert.ToBase64String(byteImage);
- }
- }
- }
- else
- {
- //var bitMap = GenCode128.Code128Rendering.MakeBarcodeImage(barcode, 1, false);
- Barcode128 code128 = new Barcode128();
- code128.CodeType = Barcode.CODE128;
- code128.ChecksumText = true;
- code128.GenerateChecksum = true;
- code128.Code = barcode;
- var bitMap = new System.Drawing.Bitmap(code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White));
- using (MemoryStream ms = new MemoryStream())
- {
- bitMap.Save(ms, ImageFormat.Gif);
- byte[] byteImage = ms.ToArray();
- Convert.ToBase64String(byteImage);
- image = "data:image/Gif;base64," + Convert.ToBase64String(byteImage);
- }
- }
Add Comment
Please, Sign In to add comment