【发布时间】:2018-10-27 03:36:09
【问题描述】:
我正在使用下面的代码打印在我的 C# WinForms 中生成的条形码,但条形码扫描仪没有检测到它,我尝试使用 code 128 字体和 code39 字体但没有成功,当我使用打印时它检测生成的条形码的调酒师软件,只是不会检测到我的
这里是代码
private void txtPprice_TextChanged(object sender, EventArgs e)
{
string barcode = txtCode.Text;
string price = txtPprice.Text;
string pname = txtPname.Text;
Bitmap bitm = new Bitmap(barcode.Length * 30, 90);
using (Graphics graphic = Graphics.FromImage(bitm))
{
Font newfont = new Font("IDAutomationHC39M", 10);
Font newfont2 = new Font("Arial Black", 8);
PointF point = new PointF(10f, 10f);
SolidBrush black = new SolidBrush(Color.Black);
SolidBrush white = new SolidBrush(Color.White);
graphic.FillRectangle(white, 0, 0, bitm.Width, bitm.Height);
graphic.DrawString("*" + barcode + "*", newfont, black, point);
PointF pointPrice = new PointF(45f, 55f);
graphic.DrawString("" + pname +"", newfont2, black, pointPrice);
PointF pointPname = new PointF(90f, 75f);
graphic.DrawString("" + price + " L.E.", newfont2, black, pointPname);
PointF pointBcode = new PointF(20f, 75f);
graphic.DrawString("" + barcode + "", newfont2, black, pointBcode);
}
using (MemoryStream Mmst = new MemoryStream())
{
bitm.Save("ms", ImageFormat.Jpeg);
pictureBox1.Image = bitm;
pictureBox1.Width = bitm.Width;
pictureBox1.Height = bitm.Height;
}
}
我已尝试按照其他帖子中的建议添加和删除 *,还将字体大小从 8p 更改为 28px,但仍然没有运气 扫描仪和打印机在调酒师应用程序上工作正常
以下示例中使用的代码是 5094411
这是一张图片,以红色突出显示的文本框是字符串条形码的来源
您可以在图片中看到,在图片框中,它以 IDautomationHC39M 字体(条形码字体)显示 5094411,在 Arial 字体下方再次显示
【问题讨论】:
-
IDAutomationHC39M 是 Code39 字体,无法输出 Code128 条码。另请注意,如果您使用条形码字体,条形码具有必须预先计算的校验和。请包括示例
barcode字符串。 -
@DourHighArch 我不太确定你所说的预先计算是什么意思,我用来生成的字符串只是像 12345678 这样的数字我有一个随机数生成器到一个文本框,并使用这个值条形码字符串,所以它只是一个数字
-
我认为这是我在几个月内第 4-5 次看到(几乎)完全相同的代码和完全相同的错误。这是来自 Barcode 字体生产商的示例代码吗?无论如何,您必须打印的位图的尺寸是多少,即。您是否必须在定义的空间打印它,或者它可以随意大?或者你只需要创建一个位图然后拉伸它以适应? “未检测到”是什么意思?条码扫描器不读取或输出错误数字?
-
@Jimi 我正在尝试使用 Xprinter 标签条码打印机,纸张尺寸为 2" x 1" .. 我的意思是它根本不读取它,没有哔哔声,什么都没有,它只检测我是否使用打印机附带的 Bartender 软件进行打印
-
看看这个:Blurry and large image barcode。顺便说一句,Code39不需要校验位,可以输入原始数据,需要
*起止符号。
标签: c# barcode barcode-scanner