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);
Run Code Online (Sandbox Code Playgroud)
它的工作.我看到条形码,我能够扫描它.现在我想使用其他东西,比如Code 128因为我需要安装Font(完成)并且只是改变
Font f = new Font("Free 3 of 9", 80); 至 Font f = new Font("Code 128", 80);
之后我在窗口看到条形码.问题是我无法扫描它.我认为那是因为我没有使用正确的开始和停止标签的条形码.据我所知,必须始终有一个开始/停止char或其他什么.对于Code 128的*中的3个我不确定.在维基上有开始代码A所以我试过
Font f = new Font("<Start Code A>test<Stop>", 80);,Font f = new Font("<Start Code A>test<Stop Code A>", 80);依此类推......我无法扫描输出.因为扫描仪无法找到启动和停止char.有任何想法吗?谢谢
你在创建正确的校验和字符吗?
查看此页面以了解如何计算校验和
有关替代方案,请查看以下链接 - 这允许您创建条形码位图:
http://www.codeproject.com/KB/graphics/BarcodeLibrary.aspx?fid=470627&fr=26#xx0xx
代码 128 可以用完全正常的字体来表示。不过,它比 9 中的 3 更棘手,因为您必须在末尾包含一个校验和字符,该字符需要根据条形码的内容动态计算。还有 3 个不同的版本,每个版本都有不同的起始字符。
\n\n换句话说,条形码需要如下布局:
\n\n[start char][barcode][checksum][stop char]\nRun Code Online (Sandbox Code Playgroud)\n\ncode128的好处是比3 of 9简洁很多。
\n\n该页面帮助我制定了计算校验和的算法。
\n\n该算法的一般概述是:
\n\n条形码的每个字符都会获得分配给它的特定值,具体取决于该字符是什么以及它在条形码中的位置。
将上述 1) 中的所有值相加。
获取上面 2) 中总计的模 103 值。
在大多数情况下,校验和字符将是以下 ASCII 代码:(模值\n加 32),如上面 3) 中确定的。
有一些细微差别,我最终需要用 javascript 创建这个算法(毫无疑问)。为了我自己将来的参考并展示一些细微差别,它看起来像这样:
\n\n/*\n * This is the variable part of my barcode, I append this to a \n * static prefix later, but I need to perform logic to compute the \n * checksum for this variable. There is logic earlier that enforces \n * this variable as a 9 character string containing only digits. \n */ \nvar formIncrement = // a 9 char "digit" string variable\n\n/*\n * Dynamically compute the total checksum value (before modulus) \n * for the variable part of my barcode, I will need to get a modulus \n * from this total when I am done. If you need a variable number of \n * characters in your barcodes or if they are not all digits \n * obviously something different would have to be done here. \n */ \nvar incrementCS = ((parseInt(formIncrement.charAt(0)) + 16) * 7) +\n ((parseInt(formIncrement.charAt(1)) + 16) * 8) +\n ((parseInt(formIncrement.charAt(2)) + 16) * 9) +\n ((parseInt(formIncrement.charAt(3)) + 16) * 10) +\n ((parseInt(formIncrement.charAt(4)) + 16) * 11) +\n ((parseInt(formIncrement.charAt(5)) + 16) * 12) +\n ((parseInt(formIncrement.charAt(6)) + 16) * 13) +\n ((parseInt(formIncrement.charAt(7)) + 16) * 14) + \n ((parseInt(formIncrement.charAt(8)) + 16) * 15);\n\n/*\n * 452 is the total checksum for my barcodes static prefix (600001), \n * so it doesn\'t need to be computed dynamically, I just add it to \n * the variable checksum total determined above and then get the \n * modulus of that sum: \n */ \nvar checksum = (452 + incrementCS) % 103\n\n\nvar barcode = "\xc5\xa1600001" + formIncrement\n\n/*\n * The 0 and the 95 - 102 cases had to be defined explicitly because \n * their checksum figures do not line up with the javascript char \n * codes for some reason (see the code 128 definition table in the \n * linked page) otherwise we simply need to get the charCode of the \n * checksum + 32. I also tack on the stop char here. \n */ \nswitch (checksum) {\n case 0 :\n barcode += "\xe2\x82\xac\xc5\x93";\n break;\n case 95 :\n barcode += "\xe2\x80\x98\xc5\x93";\n break;\n case 96 :\n barcode += "\xe2\x80\x99\xc5\x93";\n break;\n case 97 :\n barcode += "\xe2\x80\x9c\xc5\x93";\n break;\n case 98 :\n barcode += "\xe2\x80\x9d\xc5\x93";\n break;\n case 99 :\n barcode += "\xe2\x80\xa2\xc5\x93";\n break;\n case 100 :\n barcode += "\xe2\x80\x93\xc5\x93";\n break;\n case 101 :\n barcode += "\xe2\x80\x94\xc5\x93";\n break;\n case 102 :\n barcode += "\xcb\x9c\xc5\x93";\n break;\n default :\n barcode += String.fromCharCode(checksum + 32) + "\xc5\x93";\n}\n\nreturn barcode;\nRun Code Online (Sandbox Code Playgroud)\n\n您可能会注意到我的示例中的开始和结束字符(\xc5\xa1、\xc5\x93)似乎与链接页面上显示的不匹配。如果我记得的话,我认为这是因为我有一些非标准的 code128 字体,这些字符被转换为正确的字符。
\n\n编辑
\n\n我检查了我的文档。看来我从这里得到了字体。专门使用该字体并使用上面的算法,我刚刚制作了一个 code128b 条形码,结果test为\xc5\xa1testw\xc5\x93,它扫描得很好。您的校验和算法似乎工作正常,因为我们都有w,但如果您收到: ,则看起来您的开始和停止代码已关闭\xc3\x8ctestw\xc3\x8e。
我特意寻找与我使用的相同的条形码字体,因为我有一种感觉,不同品牌的 code128 字体可能会实现不同的字符来表示开始和结束条形码。
\n