C# 制作条形码
来源:互联网 发布:wifi无人机软件下载 编辑:程序博客网 时间:2024/04/29 22:13
//codeusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Drawing.Imaging;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.IO;namespace WindowsFormsApplication1{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } Bitmap b; private void Form1_Load(object sender, EventArgs e) //根据字符串生成二维码 { } /// <summary> /// code39码 编码方案为宽度调节法 具体code39码其算法没有研究,总之每种编码方案的算法不一样 /// </summary> /// <param name="strSource"></param> /// <returns></returns> private Bitmap GetCode39(string strSource) { int x = 5; int y = 0; int WidLength = 2; int NarrowLength = 1; int BarCodeHeight = 50; //条形码的高度 int intSourceLength = strSource.Length; string strEncode = "010010100"; string AlphaBet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*"; //Code39的字母 string[] Code39 = { /**//* 0 */ "000110100", /**//* 1 */ "100100001", /**//* 2 */ "001100001", /**//* 3 */ "101100000", /**//* 4 */ "000110001", /**//* 5 */ "100110000", /**//* 6 */ "001110000", /**//* 7 */ "000100101", /**//* 8 */ "100100100", /**//* 9 */ "001100100", /**//* A */ "100001001", /**//* B */ "001001001", /**//* C */ "101001000", /**//* D */ "000011001", /**//* E */ "100011000", /**//* F */ "001011000", /**//* G */ "000001101", /**//* H */ "100001100", /**//* I */ "001001100", /**//* J */ "000011100", /**//* K */ "100000011", /**//* L */ "001000011", /**//* M */ "101000010", /**//* N */ "000010011", /**//* O */ "100010010", /**//* P */ "001010010", /**//* Q */ "000000111", /**//* R */ "100000110", /**//* S */ "001000110", /**//* T */ "000010110", /**//* U */ "110000001", /**//* V */ "011000001", /**//* W */ "111000000", /**//* X */ "010010001", /**//* Y */ "110010000", /**//* Z */ "011010000", /**//* - */ "010000101", /**//* . */ "110000100", /**//*' '*/ "011000100", /**//* $ */ "010101000", /**//* / */ "010100010", /**//* + */ "010001010", /**//* % */ "000101010", /**//* * */ "010010100" }; strSource = strSource.ToUpper(); //输入的字符全部转换成大写 Bitmap objBitmap = new Bitmap(((WidLength * 3 + NarrowLength * 7) * (intSourceLength + 2)) + (x * 2), BarCodeHeight + (y * 2)); //指定宽度和高度 Graphics objGraphics = Graphics.FromImage(objBitmap); objGraphics.FillRectangle(Brushes.White, 0, 0, objBitmap.Width, objBitmap.Height); for (int i = 0; i < intSourceLength; i++) { if (AlphaBet.IndexOf(strSource[i]) == -1 || strSource[i] == '*') { objGraphics.DrawString("含有非法字符",SystemFonts.DefaultFont, Brushes.Red, x, y); return objBitmap; } strEncode = string.Format("{0}0{1}", strEncode, Code39[AlphaBet.IndexOf(strSource[i])]); } strEncode = string.Format("{0}0010010100", strEncode); int intEncodeLength = strEncode.Length; int intBarWidth; //条形码的宽度 for (int i = 0; i < intEncodeLength; i++) { intBarWidth = strEncode[i] == '1' ? WidLength : NarrowLength; objGraphics.FillRectangle(i % 2 == 0 ? Brushes.Black : Brushes.White,x, y, intBarWidth, BarCodeHeight); // x += intBarWidth; } return objBitmap; } private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if(e.KeyChar==13) { b = GetCode39(this.textBox1.Text); this.pictureBox1.Image=b; } } private void btnSave_Click(object sender, EventArgs e) { SaveFileDialog savefiledialog = new SaveFileDialog(); savefiledialog.Filter = "图片格式(*.jpg)|*.jpg"; savefiledialog.Title = "保存图片"; savefiledialog.FileName = this.textBox1.Text; if (savefiledialog.ShowDialog() == DialogResult.OK) { b.Save(savefiledialog.FileName,ImageFormat.Jpeg); } } }}
- C# 制作条形码
- C# 制作39条形码
- 制作条形码
- C#条形码
- C#条形码
- C#条形码
- C#条形码
- C#条形码
- C#条形码
- EXCEL中制作条形码
- ps制作条形码
- 用Excel制作条形码
- vc制作条形码
- 制作 二维码/条形码
- c#打印条形码
- c# 条形码扫描器
- c#实现读取条形码
- 假C#条形码
- android常用控件及组件集成关系图
- C语言 字符串操作函数
- eclipse打开当前文件所在文件夹的两种方法
- URAL 1181 Cutting a Painted Polygon【递归+分治】
- HDU 4614 Vases and Flowers 解题报告
- C# 制作条形码
- Weapon
- CUDA从入门到精通(八):线程通信
- C#知识点
- tcp_v4_connect函数分析
- Linux smaps接口文件结构
- redis实现 spring-redis-data初学习
- Android 点击两次返回键退出程序
- DialogTest.java