c# – 我的条形码有问题(Code 128)
使用Font()很容易生成
3 of 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(完成)并且只是改变 字体f =新字体(“Free 3 of 9”,80); to font f = new Font(“Code 128”,80); 之后我在窗口看到条形码.问题是我无法扫描它.我认为那是因为我没有使用正确的开始和停止标签的条形码.据我所知,必须始终有一个开始/停止char或其他什么.对于Code 128的*中的3个我不确定.在维基上有开始代码A所以我试过 字体f =新字体(“<开始代码A>测试<停止>”,80);,字体f =新字体(“<开始代码A>测试<停止代码A>”,80);等等……我无法扫描输出.因为扫描仪无法找到启动和停止char.有任何想法吗?谢谢 解决方法
代码128可以用完全正确的字体表示.它比9中的3个更棘手,因为你必须在末尾包含一个校验和字符,需要根据条形码的内容动态计算.还有3个不同的版本,每个版本都有不同的开始字符.
换句话说,条形码需要布局如下: [start char][barcode][checksum][stop char] code128的好处是它比9中的3个简洁得多. This page帮助我计算算法来计算我的校验和. 该算法的一般概述是: >条形码的每个字符都会获得分配给它的特定值 有一些细微差别,我最终需要在所有事情的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 += " |