码迷,mamicode.com
首页 > 其他好文 > 详细

生成条码

时间:2017-09-03 12:21:54      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:格式   条码   ber   returns   .com   ble   space   drawing   number   

using System;

using System.Drawing;
using ZXing.QrCode;
using ZXing;
using ZXing.Common;
 
 
namespace NKO_Printer_Core
{
    public class BarcodeHelper
    {
        /// <summary>
        /// 返回生成的Bitmap对象
        /// </summary>
        /// <param name="barcodeContent">条码内容</param>
        /// <param name="barcodeFormat">条码格式</param>
        /// <param name="height">条码高度</param>
        /// <param name="width">宽度高度</param>
        /// <returns></returns>
        public static Bitmap CreateBarcode(string barcodeContent,BarcodeFormat barcodeFormat,int height,int width)
        {
            try
            {
                BarcodeWriter writer = new BarcodeWriter();
                EncodingOptions options = new QrCodeEncodingOptions
                {
                    DisableECI = true,
                    CharacterSet = "UTF-8",
                    Width = height,
                    Height = width
                };
                writer.Options = options;
                writer.Format = barcodeFormat;
                return writer.Write(barcodeContent);
                
            }
            catch (Exception e)
            {
                return null;
            }
        }
    }
}
 

System.Drawing.Bitmap img = CreateBarcode("123456", BarcodeFormat.CODE_39,30,120);
img.Save("d:/1.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);

生成条码

标签:格式   条码   ber   returns   .com   ble   space   drawing   number   

原文地址:http://www.cnblogs.com/zhang-wenbin/p/7469065.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!