1. 程式人生 > 實用技巧 >C#生成條形碼

C#生成條形碼

/// <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。