[转载]C# 条形码(Barcode)的绘制(附件下载)

baacloud免费翻墙vpn注册使用

[转载]C# 条形码(Barcode)的绘制(附件下载) – 穿梭老李 – 博客园.

网上找了一下发现大部分都是关于39的,没事就收集了一些其他方式的……

简单代码(有时间上源码)附件下载

Bitmap image = new Bitmap(image_width, barMaxHeight + ((int)new Font("@宋体", 13).Height));

using (Graphics dc = Graphics.FromImage(image))
{
Rectangle bounds = new Rectangle((image.Width-totalImageWidth)/2, 0, totalImageWidth, barMaxHeight);
Render(barcode, dc, bounds, interGlyphSpace, barMinHeight, barMinWidth, barMaxWidth);

dc.DrawString(text, new Font("@宋体", 13), Brushes.Black, (image.Width-(int)textPosition.Width)/2, image.Height-(int)textPosition.Height,StringFormat.GenericDefault);
}
image.Save(@"G:\barcode.png");
return image;
调用示例:

private void button1_Click(object sender, EventArgs e)
{
    BarcodeDraw draw = null;
    draw = InstallBarcodeDraw(draw);
    pictureBox1.Image = draw.Draw(textBox1.Text, 80);
    //x draw.Draw(textBox1.Text,80).Save(@"G:\barcode.png");
}

private BarcodeDraw InstallBarcodeDraw(BarcodeDraw draw)
{
    switch (comboBox1.Text)
    {
        case "Code11C":
            draw = BarcodeDrawFactory.GetSymbology(BarcodeSymbology.Code11C); break;
        case "Code39NC":
            draw = BarcodeDrawFactory.GetSymbology(BarcodeSymbology.Code11NC); break;

赞(0) 打赏
分享到: 更多 (0)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏