在C#中创建Code128条码

问题描述 投票:0回答:1

[我以为我很愚蠢,只写一些带有条形码字体的文本会使扫描仪读取它。似乎我错了。

因此,在阅读了有关code128条形码的一些文档之后,我了解到:

  1. 条形码以(103、104或105取决于类型开头)
  2. 然后是字符串本身
  3. 然后是字符串中每个字符的计算总和与位置的乘积模103
  4. 然后附上106

我的代码是:

public string Str = "MADS";
public string Barcode = null;

public void OnGet()
{

    int start = 104;
    int end = 106;
    int calc = start;
    Barcode = start.ToString();
    for (var i = 0; i < Str.Length; i++)
    {
        calc += (Convert.ToChar(Str[i]) - 32) * (i + 1);
        Barcode += Str[i];
    }

    double rem = calc % 103;
    Barcode += Convert.ToChar((int)rem + 32).ToString() + end;

    Console.WriteLine(Barcode);

}

我不确定条形码字符串中应包含多少内容,以便扫描仪读取它?:

  • MADS,
  • 104MADS,
  • 104MADS,106

还是我弄错了吗?

我的引用是:

Link 1Link 2

特别是“链接1”,因为我已经用扫描仪测试了该结果,并且可以正常工作。可悲的是,我无法使输出看起来像这样。

c# barcode code128
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.