有人能推荐一个(免费的商业使用)库来生成EAN-13条形码吗?
我不需要图像,只需要字符串。
我想传递产品代码,制造商代码和国家/地区(不是数字系统)作为参数。
它可以将国家/地区转换为数字系统,并将其连接在一起计算校验和。
发布于 2018-02-16 22:04:05
基本上:Ean13是一个基于模型的校验和计算:
因此,您有一个12位数字,没有校验和,然后添加校验和。
CheckSum函数:
public static string CalculateEan13(string country, string manufacturer, string product)
{
string temp = $"{country}{manufacturer}{product}";
int sum = 0;
int digit = 0;
// Calculate the checksum digit here.
for (int i = temp.Length; i >= 1; i--)
{
digit = Convert.ToInt32(temp.Substring(i - 1, 1));
// This appears to be backwards but the
// EAN-13 checksum must be calculated
// this way to be compatible with UPC-A.
if (i % 2 == 0)
{ // odd
sum += digit * 3;
}
else
{ // even
sum += digit * 1;
}
}
int checkSum = (10 - (sum % 10)) % 10;
return $"{temp}{checkSum}";
}如何自己计算您的支票数字
示例条形码号码: 501234576421
步骤1:将所有从右边开始的备用数字相加在一起
5 0 1 2 3 4 5 7 6 2 1
0+2+4+7+4+1= 18
第二步:将答案乘以3
18x3= 54
第3步:现在将剩余的数字相加
5 0 1 2 3 4 5 7 6 2 1
5+1+3+5+6+2= 22
步骤4:将步骤2和步骤3相加在一起
54 + 22 = 76
第5步:第4步与下一个第10步的区别:
76 +4= 80
检查数字=4
https://stackoverflow.com/questions/48827715
复制相似问题