我的条形码(代码128)出了点问题

问题描述 投票:7回答:3

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

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);Font f = new Font("Code 128", 80);

之后,我在窗口上看到条形码。问题是我无法扫描。我认为那是因为我没有在条形码上使用正确的startstop标签。据我了解,必须始终有一个开始/停止字符或其他字符。对于9之3中的*,代码128的*不确定。在Wiki上有Start Code A,所以我尝试过

Font f = new Font("<Start Code A>test<Stop>", 80);Font f = new Font("<Start Code A>test<Stop Code A>", 80);等等...我无法扫描输出。因为扫描仪无法找到开始和停止字符。有任何想法吗?谢谢

c# .net barcode
3个回答
4
投票

代码128可以完全用字体表示。但是,它比9中的3更棘手,因为您必须在末尾添加一个校验和字符,该字符必须根据条形码的内容进行动态计算。还有3个不同的版本,每个版本都有不同的起始字符。

换句话说,条形码需要像这样布置:

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

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

[This page帮助我制定了计算校验和的算法。

该算法的非常一般的概述是:

  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字体,而这些字符被翻译成了正确的字符。

编辑

我重新查看了我的文档。看来我从right here获得了字体。具体来说,使用该字体并使用上述算法,我为test制作了一个code128b条形码,该条形码出现在štestwœ中,它扫描良好。您的校验和算法似乎工作正常,因为我们都有w,但是如果您得到以下内容,则似乎您的开始和停止代码已关闭:ÌtestwÎ

我指出要寻找使用的相同条形码字体是因为我感觉不同品牌的code128字体可能实现不同的字符来表示开始和结束条形码。


5
投票

您是否创建了正确的校验和字符?

[查看this page以了解如何计算校验和

或者,请查看以下链接-这使您可以创建条形码位图:

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


1
投票

根据Barcode128的Wikipedia page,我认为您应该根据Bar Code Widths段落和表格使用ASCII代码208-210来分隔一个块。

© www.soinside.com 2019 - 2024. All rights reserved.