• 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;
            }

  • 相关阅读:
    【原】WPF客户端只能启动一次
    【转载】U3D 游戏引擎之游戏架构脚本该如何来写
    【转载】u3d游戏客户端架构(---)
    【转载】asp.net 后台弹出提示框
    【转载】浅谈Excel开发:一 Excel 开发概述
    MyBatis 学习
    windows下关闭指定端口服务,解决tomcat端口占用问题
    中文用户名的js检验正则
    演讲稿
    面向对象和面向过程,python中的类class,python中程序的入口——main方法,
  • 原文地址:https://www.cnblogs.com/yuanchao/p/14538547.html
Copyright © 2020-2023  润新知