• ZXing条码图像配合Zebra打印


    利用ZXing生成条码图像的主要代码段

    using ZXing;
    using ZXing.Common;
    
    private void button1_Click(object sender, EventArgs e)
            {           
                string SN = textBox1.Text;
                if (string.IsNullOrEmpty(SN))
                {
                    return;
                }
                BarcodeWriter writer = new BarcodeWriter()
                {
                    Format = BarcodeFormat.DATA_MATRIX,
                    Options =new EncodingOptions {
                        Width = 70,
                        Height = 70,
                        Margin = 2
                    }
                };
    
                Bitmap QRcode = writer.Write(SN);
    
                Bitmap bitmap = new Bitmap(360, 80);           
                Graphics g = Graphics.FromImage(bitmap);
    
                Font font = new Font("Arial", 18);
                SolidBrush brush = new SolidBrush(Color.White);
                StringFormat format = new StringFormat();
    
                g.DrawString(SN.Substring(0,17), font, brush, new Point(0, 0), format);
                g.DrawString(SN.Substring(17, 13), font, brush, new Point(0, 24), format);
                g.DrawString(SN.Substring(30), font, brush, new Point(0, 48), format);
                g.DrawImage(QRcode, new Point(280, 0));
    
                font.Dispose();
                brush.Dispose();
                format.Dispose();
    
                pictureBox1.Image = bitmap;
    
                string data = ZebraUnity.BitmapToHex(bitmap, out int to, out int row);
                g.Dispose();
    
                string zpl = string.Format("~DGR:Temp0.GRF,{0},{1},{2}", to, row, data);
                StringBuilder cmd = new StringBuilder();
                cmd.Append(zpl);
    
                cmd.Append("^XA^LH100,30");
                cmd.Append(string.Format("^FO{0},{1}",top.Value,left.Value));
                cmd.Append("^XGR:Temp0.GRF,1,1^FS");
                cmd.Append(string.Format("^PQ{0}",numericUpDown1.Value));
                cmd.Append("^XZ");
                string cmdstr = cmd.ToString();
                ZPLHelper.PrintData(cmdstr);
            }
  • 相关阅读:
    Sql Server2012连接不上问题
    WinForm的App.config写法
    (原)centos 防火墙开放端口命令
    Linux下rsync的用法
    Centos7下部署minio
    arthas简单使用
    在Docker中运行MinIO单点模式
    中台是什么
    Kubernetes K8S之Ingress详解与示例
    Rancher2.x平台搭建与使用
  • 原文地址:https://www.cnblogs.com/lakeliu/p/11969085.html
Copyright © 2020-2023  润新知