zoukankan      html  css  js  c++  java
  • 生成一维码图片

     //生成一维码图片
    private 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.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;
     
    try
    {
    image = b.Encode(type, code);
    }
    catch (Exception e)
    {
    MessageBox.Show(e.Message);
    image = null;
    }
    //SaveImage(image, Guid.NewGuid().ToString("N") + ".png");
    byte[] buffer = b.GetImageData(BarcodeLib.SaveTypes.GIF);
    return buffer;
    }
     
    //调用
    private void BuildBarcode()
    {
    string number = string.IsNullOrEmpty(textBox1.Text.Trim()) ? "Avx-(13614)-vR" : textBox1.Text.Trim();
    BarcodeLib.TYPE codeType = comboBox1.SelectedIndex == -1 ? BarcodeLib.TYPE.CODE128 : (BarcodeLib.TYPE)Enum.Parse(typeof(BarcodeLib.TYPE), comboBox1.Text);
    System.Drawing.Image image;
    int width = 250, height = 100;
    byte[] buffer = GetBarcode(height, width,
    codeType, number, out image);
     
    pictureBox1.Image = image;
    if (image != null)
    pictureBox1.SizeMode = image.Height > pictureBox1.Height ? PictureBoxSizeMode.Zoom : PictureBoxSizeMode.Normal;
    }
    QQ:83199235
  • 相关阅读:
    利用node搭建本地服务器调试代码
    WCF与WebService的区别
    图解HTTPS
    XMAL语法系列之-(2)---WPF控件继承图
    俩种分页的实现!
    设置二级域名共享一级域名Cookie和删除共享Cookie
    Jquery 操作IFrame
    sql中的常见的全局变量
    sql字段中逗号分隔字符串的判断
    sql sever 字符串函数
  • 原文地址:https://www.cnblogs.com/softcg/p/6510977.html
Copyright © 2011-2022 走看看