Exemplo n.º 1
0
        /// <summary>
        /// 生成条码图片
        /// </summary>
        /// <param name="param"></param>
        /// <param name="filePath"></param>
        public static void GetBarCode(BarCodeParam param, string filePath)
        {
            var    wr  = CreateCode(param);
            Bitmap img = wr.Write(param.Content);

            img.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
        }
Exemplo n.º 2
0
        private static BarcodeWriter CreateCode(BarCodeParam param)
        {
            EncodingOptions encodeOption = new EncodingOptions();

            encodeOption.Height      = param.Height;
            encodeOption.PureBarcode = param.IsBuildCode;
            //encodeOption.Hints.Add(EncodeHintType.WIDTH, 10);

            BarcodeWriter wr = new BarcodeWriter();

            wr.Options = encodeOption;
            switch (param.CodeFormat)
            {
            case BarCodeFormat.CODE_39:
                wr.Format = BarcodeFormat.CODE_39;
                break;

            case BarCodeFormat.CODE_93:
                wr.Format = BarcodeFormat.CODE_93;
                break;

            case BarCodeFormat.CODE_128:
                wr.Format = BarcodeFormat.CODE_128;
                break;

            case BarCodeFormat.EAN_13:
                wr.Format = BarcodeFormat.EAN_13;
                break;

            default:
                throw new Exception("条码类型不能为空");
            }
            return(wr);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 生成条图片
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public static MemoryStream GetBarCode(BarCodeParam param)
        {
            var    wr  = CreateCode(param);
            Bitmap img = wr.Write(param.Content);

            using (MemoryStream ms = new System.IO.MemoryStream())
            {
                img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                return(ms);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 生成条图片
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public static string GetBarCodeString(BarCodeParam param)
        {
            var wr = CreateCode(param);
            //Bitmap img = new Bitmap(param.Width, param.Height);
            //img = wr.Write(param.Content);
            Bitmap img = wr.Write(param.Content);

            using (MemoryStream ms = new System.IO.MemoryStream())
            {
                img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                byte[] arr = new byte[ms.Length];
                ms.Position = 0;
                ms.Read(arr, 0, (int)ms.Length);
                ms.Close();
                return(Convert.ToBase64String(arr));
            }
        }