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
  • 相关阅读:
    angular.js 渲染
    HTML5 与 CSS3 jQuery部分知识总结
    下拉滚动协议文本框展示样式(不可删除文本内容)
    06对象
    05数组
    1文字与字体
    04函数
    03循环
    02运算符
    01基础
  • 原文地址:https://www.cnblogs.com/softcg/p/6510977.html
Copyright © 2011-2022 走看看