交叉二五码实验报告_第1页
交叉二五码实验报告_第2页
交叉二五码实验报告_第3页
交叉二五码实验报告_第4页
交叉二五码实验报告_第5页
已阅读5页,还剩9页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、交叉二五码实验报告专 业 班 级 姓 名 学 号 课 程 物流供应链管理与编码技术指导教师 一、实验题目交叉二五码实验二、实验目的熟悉并掌握交叉二五码的编码方式,在编码实验的过程中体现编码原则,最终生成交叉二五码。三、实验原理交叉25码是一种高密度的,可以嵌入任意数量数字的,长度可变化的数字条形码。该条形码是基于标准25码的规范改进而得来,它比标准25码有更高的密度与数据存储能力。交叉25码主要运用在物流行业与仓储业中。标准25码只用黑色条码代表数字0-9,而交叉25码既使用黑色条码也使用白色条码来代表0-9的数字。例如,标准25码会用前五个黑色条码表示第一个数字,用紧接着的五个黑色条码表示第

2、二个数字;而交叉25码是使用前五条黑色条码表示第一个数字,而用介于前五个黑色条码中的白色条码表示第二个数字。这也是交叉25码名称的来源。交叉25码是连续型、非定长、具有自动校验功能的双向条码,交叉25码的编码是以两个字符为一组(上下各一个)进行编码,其中一个字符以条编码,另一个字符以空编码,每个字符由5个单元组成(3个窄单元,2个宽单元),两个字符的条空相互交叉组合在一起。交叉25码的起始符为:窄条-窄空-窄条-窄空,0000交叉25码的终止符为:宽条-窄空-窄条,100交插25码的字符集包括数字0到9如下图示:起始符:0000,非条码字符 ,终止符:100,非条码字符。奇数:条;偶数位:空字

3、符集;数字09宽度调节编码法:编码方法以窄单元(条或空)表示逻辑值“0”,宽单元(条或空)表示逻辑值“1”。宽单元通常是窄单元的23倍。09与条或空的关系分析例子如下:0偶数位用空表示:窄窄宽宽窄 001101奇数位用条表示:宽窄窄窄宽 100012偶数位用空表示:窄宽窄窄宽 010013奇数位用条表示:宽宽窄窄窄 110004偶数位用空表示:窄窄宽窄宽 001015奇数位用条表示:宽窄宽窄窄 101006奇数位用空表示:窄宽宽窄窄 011007奇数位用条表示:窄窄窄宽宽 000118偶数位用空表示:宽窄窄宽窄 100109奇数位用条表示:窄宽窄宽窄 01010总结:起始0000 110001

4、 201001 311000 400101510100 601100 700011 810010 901010000110 终止100四、实验步骤1. 先打开visual c+并新建项目。在lib目录下输入编好的代码,如下图:2.点击运行调试3.输入我的学号“2011115040415”后点击Encode按键,生成一个交叉二五码:五、实验主要代码1.Program.cs :using System;using System.Collections.Generic;using System.Windows.Forms;namespace Barcoder static class Program

5、 / / The main entry point for the application. / STAThread static void Main() Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm(); 2.MainForm.cs :using System;using System.Collections.Generic;using System.ComponentModel;using System.

6、Data;using System.Drawing;using System.Text;using System.Windows.Forms;using BarcoderLib;namespace Barcoder public partial class MainForm : Form public MainForm() InitializeComponent(); private void exitToolStripMenuItem_Click(object sender, EventArgs e) this.Close(); private void aboutToolStripMenu

7、Item_Click(object sender, EventArgs e) AboutBox aboutBox1 = new AboutBox(); aboutBox1.ShowDialog(); private void MainForm_Load(object sender, EventArgs e) private void cmdEncode_Click(object sender, EventArgs e) cmdSave.Enabled = false; try switch (cboFormat.Text.Trim() case Interleaved 2 of 5: Barc

8、odeInter2of5 encoderInter2of5 = new BarcodeInter2of5(); picOutput.Image = encoderInter2of5.Encode(txtMessage.Text.Trim(); cmdSave.Enabled = true; break; catch (Exception ex) MessageBox.Show(ex.Message, Error, MessageBoxButtons.OK); private void cmdSave_Click(object sender, EventArgs e) saveFileDialo

9、g1.ShowDialog(); if (saveFileDialog1.FileName != ) / Saves the Image via a FileStream created by the OpenFile method. System.IO.FileStream fs = (System.IO.FileStream)saveFileDialog1.OpenFile(); / Saves the Image in the appropriate ImageFormat based upon the / File type selected in the dialog box. /

10、NOTE that the FilterIndex property is one-based. switch (saveFileDialog1.FilterIndex) case 1: picOutput.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg); break; case 2: picOutput.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Bmp); break; case 3: picOutput.Image.Save(fs, System.Drawing.Ima

11、ging.ImageFormat.Gif); break; fs.Close(); private void cboFormat_SelectedIndexChanged(object sender, EventArgs e) if (cboFormat.SelectedItem.ToString().Trim() = MSI) cboModulo.Visible = true; if (cboModulo.SelectedItem.ToString() = Modulo 11) | (cboModulo.SelectedItem.ToString() = Modulo 1011) | (cb

12、oModulo.SelectedItem.ToString() = Modulo 1110) cboWeightType.Visible = true; else cboWeightType.Visible = false; else cboModulo.Visible = false; cboWeightType.Visible = false; private void cboModulo_SelectedIndexChanged(object sender, EventArgs e) if (cboModulo.SelectedItem.ToString() = Modulo 11) |

13、 (cboModulo.SelectedItem.ToString() = Modulo 1011) | (cboModulo.SelectedItem.ToString() = Modulo 1110) cboWeightType.Visible = true; else cboWeightType.Visible = false; 3.BarcodeInter2of5.cs :using System;using System.Collections.Generic;using System.Text;using System.Drawing;using System.Text.Regul

14、arExpressions;namespace BarcoderLib public class BarcodeInter2of5 private string gLeftGuard = 1010; private string gRightGuard = 01101; private string gOdd = 1011001, 1101011, 1001011, 1100101, 1011011, 1101101, 1001101, 1010011, 1101001, 1001001 ; private string gEven = 0100110, 0010100, 0110100, 0

15、011010, 0100100, 0010010, 0110010, 0101100, 0010110, 0110110 ; public Bitmap Encode(string message) string encodedMessage; Bitmap barcodeImage = new Bitmap(250, 100); Graphics g = Graphics.FromImage(barcodeImage); Validate(message); encodedMessage = EncodeBarcode(message); PrintBarcode(g, encodedMes

16、sage, message, 350, 100); return barcodeImage; private void Validate(string message) Regex reNum = new Regex(d+$); if (reNum.Match(message).Success = false) throw new Exception(Encode string must be numeric); private void PrintBarcode(Graphics g, string encodedMessage, string message, int width, int

17、 height) SolidBrush whiteBrush = new SolidBrush(Color.White); SolidBrush blackBrush = new SolidBrush(Color.Black); Font textFont = new Font(FontFamily.GenericMonospace, 10, FontStyle.Regular); g.FillRectangle(whiteBrush, 0, 0, width, height); int xPos = 20; int yTop = 10; int barHeight = 50; for (in

18、t i = 0; i encodedMessage.Length; i+) if (encodedMessagei = 1) g.FillRectangle(blackBrush, xPos, yTop, 1, barHeight); xPos += 1; xPos = 20; yTop += barHeight - 2; for (int i = 0; i message.Length; i+) g.DrawString(messagei.ToString().Trim(), textFont, blackBrush, xPos, yTop); xPos += 7; private string EncodeBarcode(string message) int i; string encodedString = gLeftGuard; for (i = 0; i message.Length; i+) if (i % 2) = 0) encodedString += gOddConvert.ToInt32(messagei.ToString(); else encodedString += gEvenConvert.ToInt32(messagei.ToString(); encodedString += gRightGuard; return en

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论