2017-08-06 70 views
0

enter image description here带有字符的禅宗条码。 Winforms

嗨没有人知道如何在底部包含数字/字符串时,它绘制条形码?

这里是我的代码

 private void btnGenerate_Click_1(object sender, EventArgs e) 
    { 
     Zen.Barcode.Code128BarcodeDraw barcode = Zen.Barcode.BarcodeDrawFactory.Code128WithChecksum; 
     pictureBox1.Image = barcode.Draw(textBox1.Text, 50); 
    } 

PS我应该把它保存在一个数据库中列有过打电话了吗?谢谢

更新基地从先生VVatashi回答。这里是新的输出。

enter image description here

但它我希望它看起来像这样的条形码重叠: enter image description here

谢谢

+2

如果你还不知道如何使用Graphics.FromImage(),然后保持简单,把一个标签的图片框的下方。没有必要将条形码放入数据库,只保存文本。 –

回答

0

可以与System.Drawing中的图像打印文本,根据你的代码:

Zen.Barcode.Code128BarcodeDraw barcode = Zen.Barcode.BarcodeDrawFactory.Code128WithChecksum; 
var image = barcode.Draw(textBox1.Text, 50); 

using (var graphics = Graphics.FromImage(image)) 
using (var font = new Font("Consolas", 12)) // Any font you want 
using (var brush = new SolidBrush(Color.White)) 
using (var format = new StringFormat() { LineAlignment = StringAlignment.Far }) // To align text above the specified point 
{ 
    // Print a string at the left bottom corner of image 
    graphics.DrawString(textBox1.Text, font, brush, 0, image.Height, format); 
} 

pictureBox1.Image = image; 

这有点不清楚数据库如何与第一部分相关 你的问题。

更新。 哦,我没有注意到生成的条形码图是整个图像。在这种情况下,你可以画条形码和文本更大的图像:

Zen.Barcode.Code128BarcodeDraw barcode = Zen.Barcode.BarcodeDrawFactory.Code128WithChecksum; 
var barcodeImage = barcode.Draw(textBox1.Text, 50); 

var resultImage = new Bitmap(barcodeImage.Width, barcodeImage.Height + 20); // 20 is bottom padding, adjust to your text 

using (var graphics = Graphics.FromImage(resultImage)) 
using (var font = new Font("Consolas", 12)) 
using (var brush = new SolidBrush(Color.Black)) 
using (var format = new StringFormat() 
{ 
    Alignment = StringAlignment.Center, // Also, horizontally centered text, as in your example of the expected output 
    LineAlignment = StringAlignment.Far 
}) 
{ 
    graphics.Clear(Color.White); 
    graphics.DrawImage(barcodeImage, 0, 0); 
    graphics.DrawString(textBox1.Text, font, brush, resultImage.Width/2, resultImage.Height, format); 
} 

pictureBox1.Image = resultImage; 
+0

先生它的工作,但数字是重叠的条形码。等待病后张贴问题 – FutureDev

+0

@FutureDev,我更新了答案。 –

+0

谢谢你,先生。条形码扫描仪是否可读? – FutureDev

相关问题