条形码(代码128)字体不能扫描有问题 [英] Something wrong with barcode (Code 128) font not scanning

查看:20
本文介绍了条形码(代码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 = new Font("Free 3 of 9", 80);Font f = new Font("Code 128", 80);

在那之后,我看到我的窗户上有一个条形码。问题是我不能扫描它。我认为这是因为我没有为条形码使用正确的开始停止标记。正如我所理解的那样,总得有一个开始/停止字符或其他什么。对于9个代码中的3个,代码128的*我不确定。在Wiki上有开始代码A,所以我尝试了

Font f = new Font("<Start Code A>test<Stop>", 80);Font f = new Font("<Start Code A>test<Stop Code A>", 80);等等...我无法扫描输出。因为扫描仪找不到开始和结束字符。有什么主意吗?谢谢您

推荐答案

代码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)所确定。

    /li>

有一些细微的差别,我最终需要在所有东西的Java脚本中创建这个算法(没有问题)。为了供我将来参考,并显示一些细微差别,它看起来是这样的:

/*
 * 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;

您可能注意到,我的示例(š,œ)中的开始字符和结束字符似乎与链接页面上显示的字符不匹配。如果我没记错的话,我想是因为我有一些非标准的代码128字体,而这些字符被翻译成正确的字符。

编辑

我重新查看了我的文档。看起来我的字体是从right here得到的。使用该字体并使用上述算法,我刚刚为test制作了一个代码128b条形码,结果显示为štestwœ,扫描效果良好。您的校验和算法似乎工作得很好,因为我们都有w,但如果您得到:ÌtestwÎ,则您的开始和停止代码似乎已关闭。

我特意寻找我正在使用的相同条形码字体,因为我有一种感觉,不同品牌的code128字体可能实现不同的字符来表示开始和结束条形码。

这篇关于条形码(代码128)字体不能扫描有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆