zoukankan      html  css  js  c++  java
  • 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;
            }

  • 相关阅读:
    Java编程思想读书笔记 第十章 内部类
    利用lambda和条件表达式构造匿名递归函数
    概率论与数理统计-课程小报告
    leetcode226 翻转二叉树
    leetcode199 二叉树的右视图
    leetcode114- 二叉树展开为链表
    leetcode145 二叉树的后序遍历 特别注意迭代
    leet144 二叉树的前序遍历
    leetcode113 路径总和2 特别关注
    leetcode 112 路径总和 特别关注
  • 原文地址:https://www.cnblogs.com/yuanchao/p/14538547.html
Copyright © 2011-2022 走看看