private static Bitmap DrawOpticianLabel(string optician, DateTime operationTime, float dpi, float bs) { var fontCN8 = new Font("Arial", 8f * bs); var fontEN6 = new Font("Arial", 6f * bs); var widthPX = DrawTools.Millimeter2Pix(38, dpi); var heightPX = DrawTools.Millimeter2Pix(20, 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(12, dpi); //开始绘画 DrawString(graphics, "配镜师:" + optician, fontCN8, Color.Black, x, y); y += fontCN8.Height; DrawString(graphics, operationTime.ToString("yyyy-MM-dd HH:mm"), fontEN6, Color.Black, x, y); graphics.Save(); graphics.Dispose(); return(bitmap); }
private static Bitmap DrawOrderLabel(OrderLabelInfo orderLabelInfo, float dpi, float bs) { var fontEN = new Font("Arial", 6f * bs); //var fontCN = new Font("微软雅黑", 6f * bs); var widthPX = DrawTools.Millimeter2Pix(38, dpi); var heightPX = DrawTools.Millimeter2Pix(20, 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, fontEN, Color.Black, x, y); y += fontEN.Height; DrawString(graphics, orderLabelInfo.FrameGoodsName, fontEN, Color.Black, x, y); y += fontEN.Height; DrawString(graphics, orderLabelInfo.GlassGoodsName, fontEN, Color.Black, x, y); y += fontEN.Height; DrawString(graphics, orderLabelInfo.RightEyeInfo, fontEN, Color.Black, x, y); y += fontEN.Height; DrawString(graphics, orderLabelInfo.LeftEyeInfo, fontEN, Color.Black, x, y); //做旋转 bitmap.RotateFlip(RotateFlipType.Rotate180FlipY); bitmap.RotateFlip(RotateFlipType.Rotate180FlipX); graphics.Save(); graphics.Dispose(); return(bitmap); }
private void textBox_Height_TextChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(label_height.Text)) { LabelHeight = (int)DrawTools.Millimeter2Pix(float.Parse(textBox_Height.Text), 192f); //label_height.Text = LabelHeight.ToString(); } }
/// <summary> /// 打印镜片标签图片 /// </summary> /// <param name="widthMM"></param> /// <param name="heightMM"></param> /// <param name="dpi"></param> /// <param name="optician">配镜师</param> /// <param name="operationTime"></param> /// <param name="orderLabelInfo"></param> /// <param name="checker">检验师</param> /// <param name="logoName"></param> /// <returns></returns> public static Image DrawToOpticImage(int widthMM, int heightMM, float dpi, string optician, DateTime operationTime, OrderLabelInfo orderLabelInfo, string checker, string logoName) { float bs = dpi / DrawTools.CURRENT_DPI; var widthPX = DrawTools.Millimeter2Pix(widthMM, dpi); var heightPX = DrawTools.Millimeter2Pix(heightMM, 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 = 1; // 间隔空隙 y += DrawTools.Millimeter2Pix(2, dpi); var logImg = Image.FromFile(Framework.Common.ServerInfo.SystemPath + string.Format(@"\Logo\{0}.jpg", logoName)); var logbp = GetThumbnail(logImg, DrawTools.Millimeter2Pix(10, dpi), DrawTools.Millimeter2Pix(20, dpi)); DrawImage(graphics, logbp, (widthPX - logbp.Width) / 2, y); // 间隔空隙 y += logbp.Height + DrawTools.Millimeter2Pix(1, dpi); //绘画订单信息标签 var orderLabel = DrawOpticOrderLabel(widthMM, heightMM - 14, optician, operationTime, orderLabelInfo, checker, dpi, bs); DrawImage(graphics, orderLabel, X, y); //下一张间隔 //y += opticianLabel.Height-14; //y += DrawTools.Millimeter2Pix(14, dpi); //绘画配镜师标签 //var opticianLabel = DrawOpticOperationLabel(optician,operationTime, dpi, bs); //DrawImage(graphics, opticianLabel, 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); }
/// <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="widthMM"></param> /// <param name="heightMM"></param> /// <param name="dpi"></param> /// <param name="optician">配镜师</param> /// <param name="operationTime"></param> /// <param name="orderLabelInfo"></param> /// <param name="checker">检验师</param> /// <returns></returns> public static Image DrawToImage(int widthMM, int heightMM, float dpi, string optician, DateTime operationTime, OrderLabelInfo orderLabelInfo, string checker) { float bs = dpi / DrawTools.CURRENT_DPI; var widthPX = DrawTools.Millimeter2Pix(widthMM, dpi); var heightPX = DrawTools.Millimeter2Pix(heightMM, 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 opticianLabel = DrawOpticianLabel(optician, operationTime, dpi, bs); DrawImage(graphics, opticianLabel, X, y); //下一张间隔 //y += opticianLabel.Height-14; y += DrawTools.Millimeter2Pix(14, dpi); //绘画订单信息标签 var orderLabel = DrawOrderLabel(orderLabelInfo, 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); }
//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); }
/// <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); }
private void Print_PrintPage(object sender, PrintPageEventArgs e) { var document = sender as GlassGoodsPrintDocument; if (document != null) { GoodsBarcodeInfo currentGoodsBarcodeInfo = document.CurrentGoodsBarcodeInfo; var goodsInfo = new DrawGoodsInfo { GoodsCode = currentGoodsBarcodeInfo.GoodsCode, GoodsName = currentGoodsBarcodeInfo.GoodsName, SellPrice = currentGoodsBarcodeInfo.SellPrice }; Image image = document.DrawLabel.DrawToImage(goodsInfo); e.Graphics.DrawImage(image, DrawTools.Millimeter2Pix(1f), DrawTools.Millimeter2Pix(1f), DrawTools.Millimeter2Pix(document.DrawLabel.Width), DrawTools.Millimeter2Pix(document.DrawLabel.Height)); } }
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); }
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); }
private static Bitmap DrawPriceLabel(int width, string goodsName, string salePrice, float dpi, float bs) { var fontCN = new Font("微软雅黑", 9 * bs); var fontEN8 = new Font("微软雅黑", 9 * bs); var widthPX = DrawTools.Millimeter2Pix(width, dpi); var heightPX = DrawTools.Millimeter2Pix(18, 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 = 1; var x = DrawTools.Millimeter2Pix(3, dpi); //开始绘画 IList <string> list = DrawTools.ProcessStringLines(goodsName); if (list.Count > 2) { fontCN = new Font("微软雅黑", 8 * bs); } foreach (string str in list) { graphics.DrawString(str, fontCN, new SolidBrush(Color.Black), new PointF(3 + DrawTools.Millimeter2Pix(10f), y)); y += fontCN.Height; } DrawString(graphics, "全国统一价格:" + salePrice.Split('.')[0] + "元", fontEN8, Color.Black, x, y); //做旋转 bitmap.RotateFlip(RotateFlipType.Rotate180FlipY); bitmap.RotateFlip(RotateFlipType.Rotate180FlipX); graphics.Save(); graphics.Dispose(); return(bitmap); }
/// <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); }
private void printDoc_PrintPage(object sender, PrintPageEventArgs e) { e.Graphics.DrawImage(pictureBox1.Image, 3, 3, (int)DrawTools.Millimeter2Pix(float.Parse(textBox_Width.Text)), (int)DrawTools.Millimeter2Pix(float.Parse(textBox_Height.Text))); }