百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 编程网 > 正文

开源项目barcodelib-C#条形码图像生成库

yuyutoo 2025-05-26 19:56 11 浏览 0 评论

介绍

该库旨在为开发人员提供一个简单的类,以便他们在需要根据数据字符串生成条形码图像时使用。

用法

该库包含一个名为BarcodeLib的类,其中包含三个构造函数:

Barcode();Barcode(string);Barcode(string, BarcodeLib.TYPE);


如果决定使用参数创建实例,则参数如下:字符串是要编码到条形码中的数据,而BarcodeLib.TYPE是用于编码数据的符号体系。如果在创建实例时未选择指定数据和类型,则可以稍后(但在编码之前)通过适当的属性指定它们。

BarcodeLib.Barcode b = new BarcodeLib.Barcode();Image img = b.Encode(BarcodeLib.TYPE.UPCA, "038000356216", Color.Black, Color.White, 290, 120);
privatevoid btnEncode_Click(object sender, EventArgs e) { errorProvider1.Clear(); int W = Convert.ToInt32(this.txtWidth.Text.Trim()); int H = Convert.ToInt32(this.txtHeight.Text.Trim()); b.Alignment = AlignmentPositions.CENTER;
//barcode alignmentswitch (cbBarcodeAlign.SelectedItem.ToString().Trim().ToLower()) {case"left": b.Alignment = AlignmentPositions.LEFT; break;case"right": b.Alignment = AlignmentPositions.RIGHT; break;default: b.Alignment = AlignmentPositions.CENTER; break; }//switch
TYPE type = TYPE.UNSPECIFIED;switch (cbEncodeType.SelectedItem.ToString().Trim()) {case"UPC-A": type = TYPE.UPCA; break;case"UPC-E": type = TYPE.UPCE; break;case"UPC 2 Digit Ext.": type = TYPE.UPC_SUPPLEMENTAL_2DIGIT; break;case"UPC 5 Digit Ext.": type = TYPE.UPC_SUPPLEMENTAL_5DIGIT; break;case"EAN-13": type = TYPE.EAN13; break;case"JAN-13": type = TYPE.JAN13; break;case"EAN-8": type = TYPE.EAN8; break;case"ITF-14": type = TYPE.ITF14; break;case"Codabar": type = TYPE.Codabar; break;case"PostNet": type = TYPE.PostNet; break;case"Bookland/ISBN": type = TYPE.BOOKLAND; break;case"Code 11": type = TYPE.CODE11; break;case"Code 39": type = TYPE.CODE39; break;case"Code 39 Extended": type = TYPE.CODE39Extended; break;case"Code 39 Mod 43": type = TYPE.CODE39_Mod43; break;case"Code 93": type = TYPE.CODE93; break;case"LOGMARS": type = TYPE.LOGMARS; break;case"MSI": type = TYPE.MSI_Mod10; break;case"Interleaved 2 of 5": type = TYPE.Interleaved2of5; break;case"Interleaved 2 of 5 Mod 10": type = TYPE.Interleaved2of5_Mod10; break;case"Standard 2 of 5": type = TYPE.Standard2of5; break;case"Standard 2 of 5 Mod 10": type = TYPE.Standard2of5_Mod10; break;case"Code 128": type = TYPE.CODE128; break;case"Code 128-A": type = TYPE.CODE128A; break;case"Code 128-B": type = TYPE.CODE128B; break;case"Code 128-C": type = TYPE.CODE128C; break;case"Telepen": type = TYPE.TELEPEN; break;case"FIM": type = TYPE.FIM; break;case"Pharmacode": type = TYPE.PHARMACODE; break;default: MessageBox.Show("Please specify the encoding type."); break; }//switch
try {if (type != TYPE.UNSPECIFIED) {try { b.BarWidth = textBoxBarWidth.Text.Trim().Length < 1 ? : (int?)Convert.ToInt32(textBoxBarWidth.Text.Trim()); }catch (Exception ex) {thrownew Exception("Unable to parse BarWidth: " + ex.Message, ex); }try { b.AspectRatio = textBoxAspectRatio.Text.Trim().Length < 1 ? : (double?)Convert.ToDouble(textBoxAspectRatio.Text.Trim()); }catch (Exception ex) {thrownew Exception("Unable to parse AspectRatio: " + ex.Message, ex); }
b.IncludeLabel = this.chkGenerateLabel.Checked; b.RotateFlipType = (RotateFlipType)Enum.Parse(typeof(RotateFlipType), this.cbRotateFlip.SelectedItem.ToString(), true);
if (!String.IsOrEmpty(this.textBox1.Text.Trim())) b.AlternateLabel = this.textBox1.Text;else b.AlternateLabel = this.txtData.Text;
//label alignment and positionswitch (this.cbLabelLocation.SelectedItem.ToString().Trim().ToUpper()) {case"BOTTOMLEFT": b.LabelPosition = LabelPositions.BOTTOMLEFT; break;case"BOTTOMRIGHT": b.LabelPosition = LabelPositions.BOTTOMRIGHT; break;case"TOPCENTER": b.LabelPosition = LabelPositions.TOPCENTER; break;case"TOPLEFT": b.LabelPosition = LabelPositions.TOPLEFT; break;case"TOPRIGHT": b.LabelPosition = LabelPositions.TOPRIGHT; break;default: b.LabelPosition = LabelPositions.BOTTOMCENTER; break; }//switch
//===== Encoding performed here ===== barcode.BackgroundImage = b.Encode(type, this.txtData.Text.Trim(), this.btnForeColor.BackColor, this.btnBackColor.BackColor, W, H);//===================================
//show the encoding timethis.lblEncodingTime.Text = "(" + Math.Round(b.EncodingTime, 0, MidpointRounding.AwayFromZero).ToString() + "ms)";
txtEncoded.Text = b.EncodedValue;
tsslEncodedType.Text = "Encoding Type: " + b.EncodedType.ToString();
// Read dynamically calculated Width/Height because the user is interested.if (b.BarWidth.HasValue) txtWidth.Text = b.Width.ToString();if (b.AspectRatio.HasValue) txtHeight.Text = b.Height.ToString(); }//if
//reposition the barcode image to the middle barcode.Location = new Point((this.barcode.Location.X + this.barcode.Width / 2) - barcode.Width / 2, (this.barcode.Location.Y + this.barcode.Height / 2) - barcode.Height / 2); }//trycatch (Exception ex) { MessageBox.Show(ex.Message); }//catch }//btnEncode_Click

版权和许可

Apache-2.0 License

开源地址

https://github.com/barnhill/barcodelib




相关推荐

Docker部署 chatgpt-web-midjourney-proxy:开启一站式AI与绘图

ChatGPT和Midjourney的结合无疑是创新性的突破。ChatGPT作为强大的语言模型,能够为用户提供智能的对话和文本生成服务。而Midjourney则以其出色的绘画能力,能够根据...

Cacti监控服务器配置教程(基于CentOS+Nginx+MySQL+PHP环境搭建)

具体案例:局域网内有两台主机,一台Linux、一台Windows,现在需要配置一台Cacti监控服务器对这两台主机进行监控...

那些少为人知却非常有意思好用的 Chrome 扩展

ChromeWebStoreSessionManager要睡觉了,还有网页没看完怎么办?等明天点开歷史记录重新加载?No!有这个保存当前打开的链接,下回直接打开一串网址,好顶赞有木有!!!chr...

分享一款轻量级 HTTP(S) 代理 TinyProxy

概述众所周知,我们常用的Web服务器Nginx/Apache都可以很方便的用来做为正向或反向代理服务器使用。但是它们都并不支持HTTPS的正向代理。Nginx做为正向代理不支持HT...

深入理解 WebSecurityConfigurerAdapter「源码篇」

我们继续来撸SpringSecurity源码,今天来撸一个非常重要的WebSecurityConfigurerAdapter。我们的自定义都是继承自WebSecurityConfigurer...

RPC、Web Service等几种远程监控通信方式对比

几种远程监控通信方式的介绍一.RPCRPC使用C/S方式,采用http协议,发送请求到服务器,等待服务器返回结果。这个请求包括一个参数集和一个文本集,通常形成“classname.meth...

老酒好喝,5G时代数据中心柴油发电机组以GPRS方式接入动环监控

背景:随着手机的普及,电信运营商基站越建越多,网络覆盖范围也越来越广,基本上随时随地都能通过运营商的网络上网冲浪,这给我们传统的通过有线方式实现的动环监控也提带来了新的启发:对于不具备有线传输条件的的...

为了春节红包大战,微信做了一次成功的预热!

经过上午的预告,微信在今天下午17:00正式推出了微信红包新玩法——红包照片。微信用户在朋友圈点击照片发送按钮,会看到“红包照片”选项,用户在选择发布照片之后,这张照片将被模糊处理后,再发送到朋友...

Proxy-Lite实战:3步部署+2个案例,轻松掌握轻量级网页自动化

大家好,我是何三,80后老猿,独立开发者一、Proxy-Lite模型概述...

会Python?那么你一定要试一试mitmproxy

mitmproxy是一款工具,也可以说是python的一个包,使用这个工具可以在命令行上进行抓包(现在也可以在web页面上查看上抓的数据包了),还可以对所抓到的包进行脚本处理,非常有用。和...

十大Web安全扫描工具,你知道哪些?

初入门时,喜欢将目标站点直接丢扫描器,慢慢等扫描结果,极度依赖Web扫描器;而有一些漏洞高手,善于运用运用各种工具但并不依赖工具,经常可以找到扫描工具发现不了的漏洞。一款好用的Web扫描器对于白帽子来...

鸿蒙5网页开发神器 ArkWeb:让 Web 和原生手拉手跳舞

你有没有想过,在鸿蒙应用里既能用原生代码写高性能界面,又能直接塞进一个网页?这听起来有点像把汉堡和披萨拼在一起,但ArkWeb(方舟Web)真的做到了!今天咱们就聊聊这个神奇的工具,看看它如何让...

MapReduce过程详解及其性能优化(详细)

从JVM的角度看Map和ReduceMap阶段包括:第一读数据:从HDFS读取数据1、问题:读取数据产生多少个Mapper??Mapper数据过大的话,会产生大量的小文件,由于Mapper是基于虚拟...

大数据平台建设需要掌握的14个知识

Q1、大数据分析中的实时推荐是如何实现的?@rein07某证券系统架构师:实时推荐需要使用实时处理框架结合推荐算法,从而做到对数据的实时处理和推荐。实时处理框架有Storm、Flink、Spark...

HDFS可视化管理系统设计与实现(hdfs的可靠性设计,主要依靠哪些机制来实现)

摘要:Hadoop工具核心模块包括分布式文件系统(HadoopDistributedFileSystem,HDFS)和分布式编程模型MapReduce,其中HDFS是Hadoop数据存储处理的...

取消回复欢迎 发表评论: