• C# 条形码


      private void button1_Click(object sender, EventArgs e)
            {
                BuildBarcode();
            }


             void BuildBarcode()
            {
                System.Drawing.Image image;
                int width = 200, height = 100;
                byte[] buffer = GetBarcode(height, width, BarcodeLib.TYPE.CODE128, textBox1.Text, out image);
                try
                {
                   // pictureBox1.Image.Save(@"C:\aa.bmp");

                    image.Save(@"C:\aa.bmp");
                }
                catch (Exception ex)
                {

                    MessageBox.Show(ex.Message);
                }
               
            }


            byte[] GetBarcode(int height, int width, BarcodeLib.TYPE type,
                                             string code, out System.Drawing.Image image)
            {
                image = null;
                BarcodeLib.Barcode b = new BarcodeLib.Barcode();
                b.BackColor = System.Drawing.Color.White;
                b.ForeColor = System.Drawing.Color.Black;
                b.IncludeLabel = true;
                b.Width = 50;
                b.Height = 25;
                b.Alignment = BarcodeLib.AlignmentPositions.CENTER;
                b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
                b.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
                System.Drawing.Font font = new System.Drawing.Font("verdana", 10f);
                b.LabelFont = font;

                b.Height = height;
                b.Width = width;

                image = b.Encode(type, code);
                SaveImage(image, Guid.NewGuid().ToString("N") + ".png");
             

        byte[] buffer = b.GetImageData(BarcodeLib.SaveTypes.PNG);
                return buffer;
            }

            void SaveImage(Image img, string name)
            {
                pictureBox1.Image = img;
            }

  • 相关阅读:
    如何用Python实现网络请求库中的UR解析器,面试必学
    为什么有人说 Python 多线程是鸡肋?
    router-view 与 动态组件 区别
    keep-alive
    vue 客户端渲染和服务端渲染
    js 数组对象深拷贝
    vue template标签
    Jquery中的日历插件
    HTML5中的canvas基本概念及绘图
    HTML5中的音视频处理
  • 原文地址:https://www.cnblogs.com/yuanchao/p/14538547.html
Copyright © 2020-2023  润新知