Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        //private static Bitmap DrawOpticOperationLabel(string optician, DateTime operationTime, float dpi, float bs)
        //{
        //    var fontCN7 = new Font("Arial", 7f * bs);
        //    var fontEN6 = new Font("Arial", 6f * bs);
        //    var widthPX = DrawTools.Millimeter2Pix(38, dpi);
        //    var heightPX = DrawTools.Millimeter2Pix(13, dpi);
        //    var bitmap = new Bitmap(widthPX, heightPX, PixelFormat.Format32bppPArgb);
        //    Graphics graphics = Graphics.FromImage(bitmap);
        //    bitmap.SetResolution(dpi, dpi);
        //    graphics.Clear(Color.White);

        //    //设定Y坐标
        //    var y = 5;
        //    var x = DrawTools.Millimeter2Pix(0, dpi);


        //    graphics.Save();
        //    graphics.Dispose();
        //    return bitmap;
        //}

        private static Bitmap DrawOpticOrderLabel(int widthMM, int heightMM, string optician, DateTime operationTime, OrderLabelInfo orderLabelInfo, string checker, float dpi, float bs)
        {
            var      fontNB   = new Font("Arial", 6f * bs);
            var      fontCN   = new Font("Arial", 7f * bs);
            var      widthPX  = DrawTools.Millimeter2Pix(widthMM, dpi);
            var      heightPX = DrawTools.Millimeter2Pix(heightMM, dpi);
            var      bitmap   = new Bitmap(widthPX, heightPX, PixelFormat.Format32bppPArgb);
            Graphics graphics = Graphics.FromImage(bitmap);

            bitmap.SetResolution(dpi, dpi);
            graphics.Clear(Color.White);

            //设定Y坐标
            var y = 3;
            var x = DrawTools.Millimeter2Pix(3, dpi);

            //开始绘画
            DrawString(graphics, "工单:" + orderLabelInfo.OrderNo, fontCN, Color.Black, x, y);
            y += fontCN.Height;
            DrawString(graphics, "配镜:" + optician, fontCN, Color.Black, x, y);
            y += fontCN.Height;
            DrawString(graphics, "时间: " + operationTime.ToString("yy-MM-dd HH:mm"), fontCN, Color.Black, x, y);
            y += fontCN.Height;
            DrawString(graphics, "质检:" + checker, fontCN, Color.Black, x, y);
            y += fontCN.Height;
            DrawString(graphics, "执行标准:", fontCN, Color.Black, x, y);
            y += fontCN.Height;
            DrawString(graphics, "QB-2506-2001 GB10810.1-2005", fontNB, Color.Black, x, y);
            y += fontNB.Height;
            DrawString(graphics, "QB-2682-2005 GB10810.3-2006", fontNB, Color.Black, x, y);

            y += 35;
            //条码对象
            var ex2 = new CBarcodeX
            {
                Data      = orderLabelInfo.OrderNo,
                ShowText  = false,
                Symbology = bcType.Code128,
                Font      = new Font("Arial", 12)
            };
            var barcodeImage = ex2.Image(widthPX - DrawTools.Millimeter2Pix(3, dpi), DrawTools.Millimeter2Pix(10, dpi));

            DrawImage(graphics, barcodeImage, (widthPX - barcodeImage.Width) / 2, y);//画上条码

            //做旋转
            //bitmap.RotateFlip(RotateFlipType.Rotate180FlipY);
            //bitmap.RotateFlip(RotateFlipType.Rotate180FlipX);
            graphics.Save();
            graphics.Dispose();
            return(bitmap);
        }
Ejemplo n.º 3
0
        private Bitmap DrawBarcodeLabel(int width, string barcodeText, float dpi, float bs)
        {
            var      fontCN10 = new Font("微软雅黑", 12 * bs);
            var      widthPX  = DrawTools.Millimeter2Pix(width, dpi);
            var      heightPX = DrawTools.Millimeter2Pix(14, dpi);
            var      bitmap   = new Bitmap(widthPX, heightPX, PixelFormat.Format32bppPArgb);
            Graphics graphics = Graphics.FromImage(bitmap);

            bitmap.SetResolution(dpi, dpi);
            graphics.Clear(Color.White);

            //设定Y坐标
            var y = 5;
            var x = 0;

            var barcode = new CBarcodeX
            {
                Data      = barcodeText,
                ShowText  = false,
                Symbology = bcType.Code128,
                Font      = new Font("Arial", 12)
            };

            //画出条码图片
            var barcodeImage = barcode.Image(widthPX - 10, (heightPX - 40) / 2);

            //开始绘画
            DrawImage(graphics, barcodeImage, x + 10, y);

            //绘画条码字
            y += barcodeImage.Height + 10;
            var txtW = barcodeText.Length * 12 * bs;

            DrawString(graphics, barcodeText, fontCN10, Color.Black, (widthPX - (int)txtW) / 2, y);


            graphics.Save();
            graphics.Dispose();
            return(bitmap);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 绘制框架条码
        /// </summary>
        /// <param name="barcodeText"></param>
        /// <param name="brandName"></param>
        /// <param name="marketPrice"></param>
        /// <param name="sellPrice"></param>
        /// <param name="origin"></param>
        /// <param name="width">宽度,毫米</param>
        /// <param name="height">高度,毫米</param>
        /// <param name="barcodeWeight">条码尺寸,最小1个单位</param>
        /// <param name="barType"> </param>
        /// <returns></returns>
        public static Image DrawToImage(string barcodeText, string brandName, string marketPrice, string sellPrice, string origin, int width, int height, int barcodeWeight, int barType)
        {
            barcodeText = barcodeText.ToUpper();
            Image image;
            int   barWidth  = DrawTools.Millimeter2Pix(width) * barcodeWeight;
            int   barHeight = DrawTools.Millimeter2Pix(height) * barcodeWeight;
            var   bitmap    = new Bitmap(barWidth, barHeight, PixelFormat.Format32bppPArgb);

            bitmap.SetResolution(DrawTools.CURRENT_DPI * barcodeWeight, DrawTools.CURRENT_DPI * barcodeWeight);
            Graphics graphics = Graphics.FromImage(bitmap);

            graphics.Clear(Color.White);
            if (barType > 0)
            {
                var ex2 = new CBarcodeX
                {
                    Data      = barcodeText,
                    ShowText  = true,
                    Symbology = (bcType)barType,
                    Font      = new Font("Arial", 12)
                };
                image = ex2.Image(barWidth / 2, barHeight / 2);
            }
            else
            {
                image = Code128Rendering.MakeBarcodeImage(barcodeText, barcodeWeight, 0.1f * barcodeWeight, true, true);
            }
            int x = (image.Width < (barWidth / 2)) ? (((barWidth / 2) - image.Width) / 2) : 0;
            int y = (image.Height < barHeight) ? (((barHeight - image.Height) / 2) + (5 * barcodeWeight)) : 0;

            //int num5 = image.Width;
            //int num6 = image.Height;
            if (barType > 0)
            {
                x = 15;
                y = 5 * barcodeWeight;
            }
            var font  = new Font("微软雅黑", 8f);
            int leftY = y + 5;

            graphics.DrawString("建议零售价:" + marketPrice, font, new SolidBrush(Color.Black), new PointF(x, leftY));
            leftY += font.Height + 15;
            graphics.DrawImage(image, x, leftY, image.Width, image.Height);
            //leftY += image.Height;
            //graphics.DrawString(barcodeText, new Font("Arial", 8), new SolidBrush(Color.Black), new PointF(x, leftY));
            IList <string> list   = DrawTools.ProcessStringLines(brandName);
            int            num7   = barWidth / 2;
            float          rightY = y;
            var            font2  = new Font("微软雅黑", 8f);

            foreach (string str in list)
            {
                graphics.DrawString("品牌:" + str, font2, new SolidBrush(Color.Black), new PointF(num7 + DrawTools.Millimeter2Pix(10f), rightY));
                rightY += font2.Height + (5 * barcodeWeight);
            }
            if (origin != string.Empty)
            {
                graphics.DrawString("产地:" + origin, font2, new SolidBrush(Color.Black),
                                    new PointF(num7 + DrawTools.Millimeter2Pix(10f), rightY));
                rightY += font2.Height + (5 * barcodeWeight);
            }
            else
            {
                rightY += 3;
            }
            var font3 = new Font("微软雅黑", 9f, FontStyle.Bold);

            graphics.DrawString("可得价:" + sellPrice, font3, new SolidBrush(Color.Black), new PointF(num7 + DrawTools.Millimeter2Pix(10f), rightY));
            graphics.Save();
            return(bitmap);
        }