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帮助我计算算法来计算我的校验和.

该算法的一般概述是:

>条形码的每个字符都会获得分配给它的特定值
取决于角色是什么以及它在哪里
条码.
>上面1)中的所有值都加在一起.
>获取上面2)中总数的模数103值.
>在大多数情况下,校验和字符将是以下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字体,这些字符转换为正确的字符.

编辑

我在文档中查了回来.看起来我从right here获得了字体.使用上面的算法专门使用该字体,我只是做了一个code128b条形码进行测试,它出来了štestwœ,它扫描得很好.你的校验和算法似乎工作正常,因为我们都有w但看起来如果你得到你的开始和停止代码:ÌtestwÎ.

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

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...