网上下的用C#写的code128的生成代码,一些问题请教。
private int[] StringToCode128(string AsciiData) //为什么要把从键盘输入的字符,如"1234ABCD"做一下转换,希望高人把这下面的代码大概说一下。
{
// turn the string into ascii byte data
byte[] asciiBytes = Encoding.ASCII.GetBytes(AsciiData);
// decide which codeset to start with,
Code128Code.CodeSetAllowed csa1 = asciiBytes.Length > 0 ? Code128Code.CodesetAllowedForChar(asciiBytes[0]) : Code128Code.CodeSetAllowed.CodeAorB;
Code128Code.CodeSetAllowed csa2 = asciiBytes.Length > 0 ? Code128Code.CodesetAllowedForChar(asciiBytes[1]) : Code128Code.CodeSetAllowed.CodeAorB;
CodeSet currcs = GetBestStartSet(csa1, csa2);
// set up the beginning of the barcode,
//使用大小可按需动态增加的数组实现 IList 接口。
//长度+3
System.Collections.ArrayList codes = new System.Collections.ArrayList(asciiBytes.Length + 3); // assume no codeset changes, account for start, checksum, and stop
codes.Add(Code128Code.StartCodeForCodeSet(currcs)); //设置起始点
// add the codes for each character in the string
for (int i = 0; i < asciiBytes.Length; i++)
{
int thischar = asciiBytes[i];
int nextchar = asciiBytes.Length > (i + 1) ? asciiBytes[i + 1] : -1;
codes.AddRange(Code128Code.CodesForChar(thischar, nextchar, ref currcs));
}
// calculate the check digit
int checksum = (int)(codes[0]);
for (int i = 1; i < codes.Count; i++)
{
checksum += i * (int)(codes[i]);
}
codes.Add(checksum % 103);
codes.Add(Code128Code.StopCode());
int[] result = codes.ToArray(typeof(int)) as int[];
return result;
}
还有一处:
width = ((codes.Length - 3) * 11 + 35) * BarWeight; //这个条码显示宽度为什么要-3然后*11,再+35,具体什么含义。
如果大侠们能留个qq号更好。
谢谢。