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

本文提供了一段用于绘制条形码的C#代码示例,包括如何设置条形码的高度、宽度等属性,并展示了如何将条形码保存为图片文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

网上找了一下发现大部分都是关于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;

2011031911533394.png

2011031911550637.png
2011031911561092.png
调用示例:
        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;
//省略……
            }
            return draw;
        }
 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;

    
1 Bitmap image = new Bitmap(image_width, barMaxHeight + (( int ) new Font( " @宋体 " , 13 ).Height));
2
3 using (Graphics dc = Graphics.FromImage(image))
4 {
5 Rectangle bounds = new Rectangle((image.Width - totalImageWidth) / 2 , 0 , totalImageWidth, barMaxHeight);
6 Render(barcode, dc, bounds, interGlyphSpace, barMinHeight, barMinWidth, barMaxWidth);
7
8 dc.DrawString(text, new Font( " @宋体 " , 13 ), Brushes.Black, (image.Width - ( int )textPosition.Width) / 2 , image.Height - ( int )textPosition.Height,StringFormat.GenericDefault);
9 }
10 image.Save( @" G:\barcode.png " );
11 return image;

转载于:https://www.cnblogs.com/mzlee/archive/2011/03/19/Lee_Barcode.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值