/// <summary> /// 生成条形码 /// </summary> /// <param name="height">图片高度设置(px单位)</param> /// <param name="width">图片宽度设置(px单位)</param> /// <param name="type"></param> /// <param name="code">字符串编码</param> /// <param name="image"> System.Drawing.Image类型图片</param> /// <param name="fileSaveUrl"></param> public static void GetBarcode(int height, int width, BarcodeLib.TYPE type, string code, out System.Drawing.Image image) { try { image = null; BarcodeLib.Barcode b = new BarcodeLib.Barcode(); b.BackColor = System.Drawing.Color.White;//图片背景颜色 b.ForeColor = System.Drawing.Color.Black;//条码颜色 b.IncludeLabel = true; b.Alignment = BarcodeLib.AlignmentPositions.CENTER; b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER; b.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;//图片格式 System.Drawing.Font font = new System.Drawing.Font("verdana", 10f);//字体设置 b.LabelFont = font; b.Height = height; b.Width = width; image = b.Encode(type, code);//生成图片 } catch (Exception ex) { image = null; AppLog.Write(ex.ToString(), LogMessageType.Error); } }
需要调用 BarcodeLib.dll。