C# 使用斑马打印机打印图片
本文禁止转载,仅供参考
斑马打印机打印自定义图片思路
- 利用C#的Graphic类在自己程序中绘制出自己想要的打印效果图【简单粗暴,就是繁琐,要一直调整图片的样式,发布IIS可用】 或者使用CopyFromScreen()调用windows GDI32 API函数进行屏幕截图【有个问题是发布IIS 客户端截图失败,不能指定句柄】,再进行图片转16进制(斑马打印机能识别的机器码),然后用~DG指令将打印效果图整张通过TCP/IP或者串口传输到打印机作为模板,然后打印时利用^XG指令调用该模板进行打印;
- 利用ZPLII指令集编写带有位置信息,字体大小,打印内容等信息的指令,利用TCP/IP或者串口传输到打印机打印;
- 利用NiceLabel、BarTender等第三方打印编辑软件,利用可视化界面(托拉拽)编辑好要打印的效果,然后调用打印机驱动进行打印;
开发案例:开发100mm*70mm的标签
实现标签图片:
实现方式:Graphic类 绘制出打印效果图,再打印
知识点
- 知识点1. Graphic类绘制图片
#region Graphic类绘制图片打印
//开始绘制图片
int initialWidth = 580, initialHeight = 392;
//设置长度宽度
Bitmap theBitmap = new Bitmap(initialWidth, initialHeight);
Graphics theGraphics = Graphics.FromImage(theBitmap);
//填充的颜色
Brush bush = new SolidBrush(System.Drawing.Color.Black);
//呈现质量
theGraphics.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
//背景色
theGraphics.Clear(System.Drawing.Color.White);
string urlImage = System.AppDomain.CurrentDomain.BaseDirectory;
System.Drawing.Font myFont;
System.Drawing.Font myFontT;
System.Drawing.Font myFontUnder;
System.Drawing.Font myFontBigUnder;
myFontT = new System.Drawing.Font("宋体", 9, FontStyle.Regular);
myFont = new System.Drawing.Font("宋体", 14, FontStyle.Regular);
myFontUnder = new System.Drawing.Font("宋体", 15, FontStyle.Regular);
myFontBigUnder = new System.Drawing.Font("Century Schoolbook", 8, FontStyle.Regular);
StringFormat geshi = new StringFormat();
geshi.Alignment = StringAlignment.Center; //居中
System.Drawing.Image img = new Bitmap(urlImage + "\Image\TPK.jpg");
//TPKimg
theGraphics.DrawImage(img, 5, 0, (float)(190), (float)(52.5));
theGraphics.DrawString("touching tomorrow,today!", myFontT, bush, 15, 55);
//Conimg
System.Drawing.Image img2 = new Bitmap(urlImage + "\Image\consignmentLabel.jpg");
theGraphics.DrawImage(img2, 196, 0, (float)(287), (float)(75));
//QRCodeimg
Image img3 = new Bitmap(urlImage + "\Image\labelQRCode.jpg");
theGraphics.DrawImage(img3, 490, 11, (float)(67), (float)(67));
int hei = 75;
int mul = 45;
int txtUnder = 20;
int txt = 15;
//txt
theGraphics.DrawString("供 应 商:", myFont, bush, 5, hei);
theGraphics.DrawString("Vendor :", myFont, bush, 5, hei + txtUnder);//+10
theGraphics.DrawString("Darwin", myFontUnder, bush, 140, hei + txt);//+5
theGraphics.DrawLine(new Pen(Color.Black), new Point(100, hei + txtUnder \* 2), new Point(250, hei + txtUnder \* 2));
theGraphics.DrawString("订单号码:", myFont, bush, 255, hei);
theGraphics.DrawString("PO NO :", myFont, bush, 255, hei + txtUnder);
theGraphics.DrawString(txtNum.Text, myFontUnder, bush, 365, hei + txt)
theGraphics.DrawLine(new Pen(Color.Black), new Point(350, hei + txtUnder * 2), new Point(500, hei + txtUnder * 2));
theGraphics.DrawString("TPK料号:", myFont, bush, 5, hei + mul