我的条形码有问题(Code 128)

使用Font()很容易生成3个9条形码

 Font f = new Font("Free 3 of 9", 80); this.Font = f; Label l = new Label(); l.Text = "*STACKOVERFLOW*"; l.Size = new System.Drawing.Size(800, 600); this.Controls.Add(l); this.Size = new Size(800, 600); 

它的工作。 我看到条形码,我能够扫描它。 现在我想使用其他东西,比如Code 128因为我需要安装Font(完成)并且只是改变

Font f = new Font("Free 3 of 9", 80); to Font f = new Font("Code 128", 80);

之后我在窗口看到条形码。 问题是我无法扫描它。 我认为那是因为我没有使用正确的开始停止标签的条形码。 据我所知,必须始终有一个开始/停止char或其他什么。 9个中的3个是Code 128的*我不确定。 在维基上有开始代码A所以我试过了

Font f = new Font("test", 80);Font f = new Font("test", 80); 等等……我无法扫描输出。 因为扫描仪无法找到启动和停止char。 有任何想法吗? 谢谢

代码128可以用完全正确的字体表示。 它比9中的3个更棘手,因为你必须在末尾包含一个校验和字符,需要根据条形码的内容动态计算。 还有3个不同的版本,每个版本都有不同的起始字符。

换句话说,条形码需要布局如下:

 [start char][barcode][checksum][stop char] 

code128的好处是它比9中的3个简洁得多。

这个页面帮助我计算出算法来计算我的校验和。

该算法的一般概述是:

  1. 条形码的每个字符都会获得分配给它的特定值,具体取决于字符的位置以及条形码的位置。

  2. 上面1)中的所有值都加在一起。

  3. 获得上面2)中总数的模数103值。

  4. 在大多数情况下,校验和字符将是以下的ASCII代码:(模数值加32),如上面3)中所确定的。

有一些细微差别,我最终需要在所有事情的javascript中创建这个算法(没有问题)。 对于我自己将来的参考和显示一些细微差别这是它的样子:

 /* * This is the variable part of my barcode, I append this to a * static prefix later, but I need to perform logic to compute the * checksum for this variable. There is logic earlier that enforces * this variable as a 9 character string containing only digits. */ var formIncrement = // a 9 char "digit" string variable /* * Dynamically compute the total checksum value (before modulus) * for the variable part of my barcode, I will need to get a modulus * from this total when I am done. If you need a variable number of * characters in your barcodes or if they are not all digits * obviously something different would have to be done here. */ var incrementCS = ((parseInt(formIncrement.charAt(0)) + 16) * 7) + ((parseInt(formIncrement.charAt(1)) + 16) * 8) + ((parseInt(formIncrement.charAt(2)) + 16) * 9) + ((parseInt(formIncrement.charAt(3)) + 16) * 10) + ((parseInt(formIncrement.charAt(4)) + 16) * 11) + ((parseInt(formIncrement.charAt(5)) + 16) * 12) + ((parseInt(formIncrement.charAt(6)) + 16) * 13) + ((parseInt(formIncrement.charAt(7)) + 16) * 14) + ((parseInt(formIncrement.charAt(8)) + 16) * 15); /* * 452 is the total checksum for my barcodes static prefix (600001), * so it doesn't need to be computed dynamically, I just add it to * the variable checksum total determined above and then get the * modulus of that sum: */ var checksum = (452 + incrementCS) % 103 var barcode = "š600001" + formIncrement /* * The 0 and the 95 - 102 cases had to be defined explicitly because * their checksum figures do not line up with the javascript char * codes for some reason (see the code 128 definition table in the * linked page) otherwise we simply need to get the charCode of the * checksum + 32. I also tack on the stop char here. */ switch (checksum) { case 0 : barcode += "€œ"; break; case 95 : barcode += "'œ"; break; case 96 : barcode += "'œ"; break; case 97 : barcode += "“œ"; break; case 98 : barcode += "”œ"; break; case 99 : barcode += "•œ"; break; case 100 : barcode += "–œ"; break; case 101 : barcode += "—œ"; break; case 102 : barcode += "˜œ"; break; default : barcode += String.fromCharCode(checksum + 32) + "œ"; } return barcode; 

您可能会注意到我的示例中的开始和停止字符(š,œ)似乎与链接页面上显示的字符不匹配。 如果我记得我认为这是因为我有一些非标准的code128字体,这些字符转换为正确的字符。

编辑

我在文档中查了回来。 看起来我从这里得到了字体。 有了这个字体并使用上面的算法,我只是做了一个code128b条码进行test ,它出来了štestwœ ,它扫描得很好。 你的校验和算法似乎工作正常,因为我们都有w但看起来你的起点和终止代码是关闭的,如果你得到: ÌtestwÎ

我指出要查找我正在使用的相同条形码字体,因为我感觉不同品牌的code128字体可以实现不同的字符来表示开始和停止条形码。

你在创建正确的校验和字符吗?

查看此页面以了解如何计算校验和

有关替代方案,请查看以下链接 – 这允许您创建条形码位图:

http://www.codeproject.com/KB/graphics/BarcodeLibrary.aspx?fid=470627&fr=26#xx0xx

查看Barcode128的维基百科页面 ,我认为您应该使用ASCII代码208-210来划分块,根据条形码宽度段落和表格。