示例#1
0
        /// <summary>
        /// 绘制框架条码
        /// </summary>
        /// <param name="drawGoodsInfo"></param>
        /// <returns></returns>
        public Image DrawToImage(DrawGoodsInfo drawGoodsInfo)
        {
            var barcodeText = drawGoodsInfo.GoodsCode.ToUpper();
            int barWidth    = DrawTools.Millimeter2Pix(Width, DPI);
            int barHeight   = DrawTools.Millimeter2Pix(Height, DPI);
            var bitmap      = new Bitmap(barWidth, barHeight, PixelFormat.Format32bppPArgb);

            bitmap.SetResolution(DPI, DPI);
            Graphics graphics = Graphics.FromImage(bitmap);

            graphics.Clear(Color.White);

            //条码对象
            var ex2 = new CBarcodeX
            {
                Data      = barcodeText,
                ShowText  = false,
                Symbology = bcType.Code128,
                Font      = new Font("Arial", 12)
            };
            var barcodeImage = ex2.Image(barWidth / 2 - DrawTools.Millimeter2Pix(4, DPI), DrawTools.Millimeter2Pix(7, DPI));

            //画左侧价格条码
            int x = DrawTools.Millimeter2Pix(3, DPI);

            DrawText(ref graphics, barcodeImage, drawGoodsInfo, barWidth, x, 0);

            //画右侧价格条码
            x = DrawTools.Millimeter2Pix(Width / 2 + 4, DPI);
            DrawText(ref graphics, barcodeImage, drawGoodsInfo, barWidth, x, barWidth / 2 + 7);

            //int y = DrawTools.Millimeter2Pix(3.5f, DPI);
            //graphics.DrawImage(barcodeImage, x, y, barcodeImage.Width, barcodeImage.Height);
            //y = y + barcodeImage.Height + 5;
            //var font = new Font("微软雅黑", 8f);

            //var stringFormat = new StringFormat
            //{
            //    LineAlignment = StringAlignment.Center,
            //    Alignment = StringAlignment.Center
            //};
            //var printTxt = "产品编号:" + drawGoodsInfo.GoodsCode;
            //var lbRect = new Rectangle(0, y, barWidth / 2, (int)font.GetHeight() + 15);
            //graphics.DrawString(printTxt, font, new SolidBrush(Color.Black), lbRect, stringFormat);
            //y = y + font.Height + 20;
            //lbRect.Y = y;
            //printTxt = "全国统一零售价:" + drawGoodsInfo.SellPrice + "元";
            //graphics.DrawString(printTxt, new Font("微软雅黑", 7f), new SolidBrush(Color.Black), lbRect, stringFormat);


            graphics.Save();
            return(bitmap);
        }
        /// <summary>
        /// 打印镜片标签图片
        /// </summary>
        /// <param name="drawGoodsInfo">需打印的商品信息</param>
        /// <returns></returns>
        public Image DrawToImage(DrawGoodsInfo drawGoodsInfo)
        {
            float    bs        = DPI / DrawTools.CURRENT_DPI;
            var      widthPX   = DrawTools.Millimeter2Pix(Width, DPI);
            var      heightPX  = DrawTools.Millimeter2Pix(Height, DPI);
            var      allBitmap = new Bitmap(widthPX, heightPX, PixelFormat.Format32bppPArgb);
            Graphics graphics  = Graphics.FromImage(allBitmap);

            allBitmap.SetResolution(DPI, DPI);
            graphics.Clear(Color.White);
            var       y = 1;
            const int X = 0;


            // 间隔空隙两张
            //y += DrawTools.Millimeter2Pix(50,dpi);

            //绘画条码
            var barcodeLabel = DrawBarcodeLabel(Width, drawGoodsInfo.GoodsCode, DPI, bs);

            DrawImage(graphics, barcodeLabel, X, y);

            //下一张间隔
            //y += opticianLabel.Height-14;
            y += DrawTools.Millimeter2Pix((float)14.5, DPI);

            //绘画订单信息标签
            var orderLabel = DrawPriceLabel(Width, drawGoodsInfo.GoodsName, drawGoodsInfo.SellPrice, DPI, bs);

            DrawImage(graphics, orderLabel, X, y);

            ////下一张间隔
            //y += orderLabel.Height;
            //y += DrawTools.Millimeter2Pix(5, dpi);

            //绘画检验师
            //var checkLabel = DrawChecker(checker, orderLabelInfo.OrderNo, dpi, bs);
            //DrawImage(graphics, checkLabel, X, y);

            //下一张间隔
            //y += checkLabel.Height;
            //y += DrawTools.Millimeter2Pix(5, dpi);

            //同样再绘画检验师
            //DrawImage(graphics, checkLabel, X, y);


            graphics.Save();
            graphics.Dispose();
            return(allBitmap);
        }
示例#3
0
        void DrawText(ref Graphics graphics, Image barcodeImage, DrawGoodsInfo drawGoodsInfo, int barWidth, int barcodeX, int textX)
        {
            int y = DrawTools.Millimeter2Pix(2f, DPI);

            graphics.DrawImage(barcodeImage, barcodeX, y, barcodeImage.Width, barcodeImage.Height);
            y = y + barcodeImage.Height + 5;

            var stringFormat = new StringFormat
            {
                LineAlignment = StringAlignment.Center,
                Alignment     = StringAlignment.Center
            };
            var printTxt = "产品编号:" + drawGoodsInfo.GoodsCode;
            var font     = new Font("微软雅黑", 8f);
            var lbRect   = new Rectangle(textX, y, barWidth / 2, (int)font.GetHeight() + 15);

            graphics.DrawString(printTxt, font, new SolidBrush(Color.Black), lbRect, stringFormat);
            y        = y + font.Height + 20;
            lbRect.Y = y;
            printTxt = "全国统一零售价:" + drawGoodsInfo.SellPrice.Split('.')[0] + "元";
            graphics.DrawString(printTxt, new Font("微软雅黑", 7f), new SolidBrush(Color.Black), lbRect, stringFormat);
        }