双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

网上下的用C#写的code128的生成代码,一些问题请教。

beiguoyouzi beiguoyouzi 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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号更好。
谢谢。
...全文
评论 4
收藏 已收藏
分享
返回顶部
beiguoyouzi
C# 111,129 成员 642,540 内容