C# 使用斑马打印机打印图片

C# 使用斑马打印机打印图片
本文禁止转载,仅供参考

斑马打印机打印自定义图片思路

  1. 利用C#的Graphic类在自己程序中绘制出自己想要的打印效果图【简单粗暴,就是繁琐,要一直调整图片的样式,发布IIS可用】 或者使用CopyFromScreen()调用windows GDI32 API函数进行屏幕截图【有个问题是发布IIS 客户端截图失败,不能指定句柄】,再进行图片转16进制(斑马打印机能识别的机器码),然后用~DG指令将打印效果图整张通过TCP/IP或者串口传输到打印机作为模板,然后打印时利用^XG指令调用该模板进行打印;
  2. 利用ZPLII指令集编写带有位置信息,字体大小,打印内容等信息的指令,利用TCP/IP或者串口传输到打印机打印;
  3. 利用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
  • 0
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值