基本信息
源码名称:C# 生成各种条码字体的条形码
源码大小:0.24M
文件格式:.rar
开发语言:C#
更新时间:2017-11-02
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
生成各种条码字体的条形码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BarcodeLib;
using System.IO;

namespace Test_Barcode
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

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

        }

        private static 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;

            image = b.Encode(type, code);
            image.RotateFlip(RotateFlipType.Rotate90FlipXY);
            //SaveImage(image, Guid.NewGuid().ToString("N")   ".png");
            byte[] buffer = b.GetImageData(SaveTypes.GIF);
            return buffer;
        }



        void BuildBarcode()
        {
            System.Drawing.Image image;
            int width = 200, height = 50;
            byte[] buffer = GetBarcode(height, width,
                     BarcodeLib.TYPE.EAN13, textBox1.Text.ToString(), out image);
            MemoryStream ms = new MemoryStream(buffer);
            pictureBox1.Width = height;
            pictureBox1.Height = width;
            pictureBox1.Image=Image.FromStream(ms); 
            //pictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipXY);
        }



        private static void SaveImage(System.Drawing.Image image, string p)
        {
            //自动保存图片到指定目录中
            string stringfilename = "D:\\"   p;
            image.Save(stringfilename, System.Drawing.Imaging.ImageFormat.Jpeg);
        }
    }
}