下载地址:http://zxingnet.codeplex.com/

zxing.net是.net平台下编解条形码和二维码的工具,使用非常方便。

本文主要说明一下多种类型条码的生成。

适用的场景,标签可视化设计时,自定义条码类型,预览。

遍历zxing支持的全部条码类型

if (rb == rb1wm){foreach (BarcodeFormat format in Enum.GetValues(typeof(BarcodeFormat))){if (format != BarcodeFormat.All_1D)cbxBarcodeFormat.Items.Add(format.ToString());}cbxBarcodeFormat.Items.Remove(BarcodeFormat.QR_CODE.ToString());cbxBarcodeFormat.Items.Remove(BarcodeFormat.AZTEC.ToString());cbxBarcodeFormat.Items.Remove(BarcodeFormat.DATA_MATRIX.ToString());cbxBarcodeFormat.Items.Remove(BarcodeFormat.PDF_417.ToString());}if (rb == rb2wm){cbxBarcodeFormat.Items.Add(BarcodeFormat.QR_CODE.ToString());cbxBarcodeFormat.Items.Add(BarcodeFormat.AZTEC.ToString());cbxBarcodeFormat.Items.Add(BarcodeFormat.DATA_MATRIX.ToString());cbxBarcodeFormat.Items.Add(BarcodeFormat.PDF_417.ToString());}

根据选择的类型生成条码

Bitmap bitmap = new Bitmap(pbxBarcode.Width, pbxBarcode.Height);Graphics g = Graphics.FromImage(bitmap);g.Clear(Color.White);Format = (BarcodeFormat)Enum.Parse(typeof(BarcodeFormat), cbxBarcodeFormat.SelectedItem.ToString());try{var options = new ZXing.Common.EncodingOptions{PureBarcode = !chxDisplayBarcode.Checked};#region 根据条码类型Write Image switch (Format){case BarcodeFormat.QR_CODE:#region QRCodeif (cbxErrorLevel.SelectedItem.ToString().Equals("L"))ErrorCorrectionLevel = QR_ErrorCorrectionLevel.L;if (cbxErrorLevel.SelectedItem.ToString().Equals("H"))ErrorCorrectionLevel = QR_ErrorCorrectionLevel.H;if (cbxErrorLevel.SelectedItem.ToString().Equals("M"))ErrorCorrectionLevel = QR_ErrorCorrectionLevel.M;if (cbxErrorLevel.SelectedItem.ToString().Equals("Q"))ErrorCorrectionLevel = QR_ErrorCorrectionLevel.Q;ErrorCorrectionLevel level = null;switch (ErrorCorrectionLevel){case QR_ErrorCorrectionLevel.H:level = ZXing.QrCode.Internal.ErrorCorrectionLevel.H;break;case QR_ErrorCorrectionLevel.M:level = ZXing.QrCode.Internal.ErrorCorrectionLevel.M;break;case QR_ErrorCorrectionLevel.L:level = ZXing.QrCode.Internal.ErrorCorrectionLevel.L;break;case QR_ErrorCorrectionLevel.Q:level = ZXing.QrCode.Internal.ErrorCorrectionLevel.Q;break;}QrCodeEncodingOptions qr_options = new QrCodeEncodingOptions{Margin = 0,DisableECI = true,CharacterSet = "UTF-8",ErrorCorrection = level,PureBarcode = !chxDisplayBarcode.Checked,Width = pbxBarcode.Width,Height = pbxBarcode.Height};var qrWriter = new ZXing.BarcodeWriter();qrWriter.Format = BarcodeFormat.QR_CODE;qrWriter.Options = qr_options;#endregionbitmap = qrWriter.Write(tbxBarcodeValue.Text.Trim());BarCodeOptionsChanged?.Invoke(qrWriter.Options, Format, bitmap);break;case BarcodeFormat.PDF_417:#region PDF417PDF417EncodingOptions pdf_options = new PDF417EncodingOptions{Margin = 0,DisableECI = true,CharacterSet = "UTF-8",Width = pbxBarcode.Width,Height = pbxBarcode.Height,PureBarcode = !chxDisplayBarcode.Checked};var pdf417Writer = new ZXing.BarcodeWriter();pdf417Writer.Format = BarcodeFormat.PDF_417;pdf417Writer.Options = pdf_options;#endregionbitmap = pdf417Writer.Write(tbxBarcodeValue.Text.Trim());BarCodeOptionsChanged?.Invoke(pdf417Writer.Options, Format, bitmap);break;case BarcodeFormat.DATA_MATRIX:#region DataMatrixDatamatrixEncodingOptions dataMatrix_options = new DatamatrixEncodingOptions{Margin = 0,SymbolShape = (ZXing.Datamatrix.Encoder.SymbolShapeHint)(Enum.Parse(typeof(ZXing.Datamatrix.Encoder.SymbolShapeHint), cbxDataMatrixOption.SelectedItem.ToString())),Width = pbxBarcode.Width,Height = pbxBarcode.Height,PureBarcode = !chxDisplayBarcode.Checked,};var dataMatrixWriter = new ZXing.BarcodeWriter();dataMatrixWriter.Format = BarcodeFormat.DATA_MATRIX;dataMatrixWriter.Options = dataMatrix_options;#endregionbitmap = dataMatrixWriter.Write(tbxBarcodeValue.Text.Trim());BarCodeOptionsChanged?.Invoke(dataMatrixWriter.Options, Format, bitmap);break;case BarcodeFormat.AZTEC:#region AztecZXing.Aztec.AztecEncodingOptions aztecEncodingOptions = new ZXing.Aztec.AztecEncodingOptions{Margin = 0,ErrorCorrection = 2,PureBarcode = !chxDisplayBarcode.Checked,Layers = 16};var aztecWriter = new ZXing.BarcodeWriter();aztecWriter.Format = BarcodeFormat.AZTEC;aztecWriter.Options = aztecEncodingOptions;#endregionbitmap = aztecWriter.Write(tbxBarcodeValue.Text.Trim());BarCodeOptionsChanged?.Invoke(aztecWriter.Options, Format, bitmap);break;case BarcodeFormat.CODE_128:#region Code128ZXing.OneD.Code128EncodingOptions code128_options = new ZXing.OneD.Code128EncodingOptions{Margin = 0,PureBarcode = !chxDisplayBarcode.Checked,Width = pbxBarcode.Width,Height = pbxBarcode.Height,ForceCodesetB = true};var code128_Writer = new ZXing.BarcodeWriter();code128_Writer.Format = BarcodeFormat.CODE_128;code128_Writer.Options = code128_options;#endregionbitmap = code128_Writer.Write(tbxBarcodeValue.Text.Trim());BarCodeOptionsChanged?.Invoke(code128_Writer.Options, Format, bitmap);break;case BarcodeFormat.CODABAR:var codeBar_Writer = new ZXing.BarcodeWriter();codeBar_Writer.Format = BarcodeFormat.CODABAR;codeBar_Writer.Options = options;bitmap = codeBar_Writer.Write(tbxBarcodeValue.Text.Trim());BarCodeOptionsChanged?.Invoke(options, Format, bitmap);break;case BarcodeFormat.EAN_13:var ean13_Writer = new ZXing.BarcodeWriter();ean13_Writer.Format = BarcodeFormat.EAN_13;ean13_Writer.Options = options;bitmap = ean13_Writer.Write(tbxBarcodeValue.Text.Trim());BarCodeOptionsChanged?.Invoke(options, Format, bitmap);break;case BarcodeFormat.EAN_8:var ean8_Writer = new ZXing.BarcodeWriter();ean8_Writer.Format = BarcodeFormat.EAN_8;ean8_Writer.Options = options;bitmap = ean8_Writer.Write(tbxBarcodeValue.Text.Trim());BarCodeOptionsChanged?.Invoke(options, Format, bitmap);break;case BarcodeFormat.CODE_39:var code39_Writer = new ZXing.BarcodeWriter();code39_Writer.Format = BarcodeFormat.CODE_39;code39_Writer.Options = options;bitmap = code39_Writer.Write(tbxBarcodeValue.Text.Trim());BarCodeOptionsChanged?.Invoke(options, Format, bitmap);break;case BarcodeFormat.UPC_A:var upca_Writer = new ZXing.BarcodeWriter();upca_Writer.Format = BarcodeFormat.UPC_A;upca_Writer.Options = options;bitmap = upca_Writer.Write(tbxBarcodeValue.Text.Trim());BarCodeOptionsChanged?.Invoke(options, Format, bitmap);break;case BarcodeFormat.UPC_E:var upce_Writer = new ZXing.BarcodeWriter();upce_Writer.Format = BarcodeFormat.UPC_E;upce_Writer.Options = options;bitmap = upce_Writer.Write(tbxBarcodeValue.Text.Trim());BarCodeOptionsChanged?.Invoke(options, Format, bitmap);break;case BarcodeFormat.MSI:var msi_Writer = new ZXing.BarcodeWriter();msi_Writer.Format = BarcodeFormat.MSI;msi_Writer.Options = options;bitmap = msi_Writer.Write(tbxBarcodeValue.Text.Trim());BarCodeOptionsChanged?.Invoke(options, Format, bitmap);break;case BarcodeFormat.ITF:var itf_Writer = new ZXing.BarcodeWriter();itf_Writer.Format = BarcodeFormat.ITF;itf_Writer.Options = options;bitmap = itf_Writer.Write(tbxBarcodeValue.Text.Trim());BarCodeOptionsChanged?.Invoke(options, Format, bitmap);break;case BarcodeFormat.PLESSEY:var plessey_Writer = new ZXing.BarcodeWriter();plessey_Writer.Format = BarcodeFormat.PLESSEY;plessey_Writer.Options = options;bitmap = plessey_Writer.Write(tbxBarcodeValue.Text.Trim());BarCodeOptionsChanged?.Invoke(options, Format, bitmap);break;case BarcodeFormat.MAXICODE:var code_Writer = new ZXing.BarcodeWriter();code_Writer.Format = BarcodeFormat.MAXICODE;code_Writer.Options = options;bitmap = code_Writer.Write(tbxBarcodeValue.Text.Trim());BarCodeOptionsChanged?.Invoke(options, Format, bitmap);break;default:throw new Exception("条码格式暂不支持!");}#endregion}catch (Exception ex){MessageBox.Show("编码生成错误:" + ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);}finally{pbxBarcode.Image = bitmap;}

  

转载于:https://www.cnblogs.com/datacool/p/datacool_2017_zxing.html

zxing .net 多种条码格式的生成相关推荐

  1. java二维码生成-谷歌(Google.zxing)开源二维码生成学习及实例

    java二维码生成-谷歌(Google.zxing)开源二维码生成的实例及介绍  这里我们使用比特矩阵(位矩阵)的QR码编码在缓冲图片上画出二维码 实例有以下一个传入参数 OutputStream o ...

  2. 动图怎么做二维码?怎么将gif格式图片生成二维码?

    如何将gif动图做成二维码呢?相信很多小伙伴经常会扫描好友制作的二维码图片后,会出现图片.视频等内容,那么静态图片生成二维码的方法相信很多小伙伴都知道,那么gif动图怎么做成二维码来展示呢?下面教大家 ...

  3. MEncoder 多种视频格式快速转压——使用手册!

    http://freetravel.blog.sohu.com/846099.html 分类: 电脑-数码2006-02-06 15:25 题目:MEncoder 多种视频格式快速转压--使用手册!( ...

  4. 设计并实现同时支持多种视频格式的流媒体点播系统

    我之前有篇文章介绍过如果实现一个C/S模式的Flv点播系统,Flv格式简单,处理起来也比较轻松,不过,实际工作中,需要点播的影片,岂会只有Flv这一种格式.我们常见的几种视频格式,随便哪一个都要比Fl ...

  5. JAVA实现基于ZXing的二维码自动生成与图片合成

    JAVA实现基于ZXing的二维码自动生成与图片合成 近日做项目需要生成带有信息的二维码,并嵌入到一张图片中.实现思路采用Zxing生成二维码,java图形库进行图片的嵌入. 生成二维码 ZXing是 ...

  6. R语言将数据列中的多种日期格式统一变化为一种固定格式实战:使用lubridate包中的parse_date_time函数

    R语言将数据列中的多种日期格式统一变化为一种固定格式实战:使用lubridate包中的parse_date_time函数 目录

  7. java时间有几种格式_java解析多种时间格式

    应用场景:在我之前有一次写Excel导入的时候,由于Excel中的单元格格式问题,用户可能会输入多种不同格式的日期格式,项目经理要求能解析多种常用的时间格式 实现的代码: /** * @param i ...

  8. 自制代码生成器 多种模版引擎 支持生成各种代码

    自制代码生成器 多种模版引擎 支持生成各种代码 支持多种数据库 工作三年了  一直伴随本人的代码生涯 贡献之大 可想而知 过程中 它也经历了各种进货 1.先来看看界面 主界面 连接数据库  支持多种主 ...

  9. python打包zip文件_python 解压文件,合并文件 打包成zip格式文件 生成MD5值

    #!/usr/bin/env python #_*_encoding:utf-8 # 2018/05/29 #augustyang #2.0 ''' 解压文件,合并文件 打包成zip格式文件 生成MD ...

最新文章

  1. 大数据学习01——配置虚拟机节点相关网络
  2. 如何使用阿里云服务器
  3. php字符串处理函数大全
  4. Lucene 4.X 倒排索引原理与实现: (3) Term Dictionary和Index文件 (FST详细解析)——直接看例子就明白了!!!...
  5. 《算法竞赛进阶指南》0.5排序
  6. 操作系统进程(作业)调度常见算法详解
  7. 前端学习(908):location常用方法
  8. Django-session的存放位置
  9. 47 - 算法 - Leetcode-160 -相交链表
  10. vSAN其实很简单-一张图搞清楚不同vSAN版本之间的功能差异
  11. tensorflow Image 解码函数
  12. css网页设计作业_运动中心网页设计作业成品
  13. 高质量解读《高性能mysql》——第1章 MySQL架构与历史
  14. java kindeditor 上传图片_使用Kindeditor上传图片
  15. 2022-08-19 mysql/stonedb-索引优化专利交底书-改进点
  16. 计算机单位厘米 像素,英尺和厘米的换算计算器 显示器的像素解析度可能不是...
  17. 视频:老外演示如何做康奈尔笔记
  18. 电子护照阅读器|酒店机场高铁自助机录入系统
  19. 微信公众号开发淘宝优惠券查询的思路和原理
  20. 华为企业交换机ACL经典案例

热门文章

  1. 【POJ - 3249】Test for Job(DAG线性求带负权的最长路,dp)
  2. 【CodeForces - 271B 】Prime Matrix (素数,预处理打表,思维)
  3. 【CodeForces - 334B】Eight Point Sets(水题模拟,有坑)
  4. 3.Programming in TensorFlow and Keras
  5. CSS定位总结:position=static/relative/absolute/fixed时的区别、top/bottom/left/right与margin外边距的运用
  6. github怎么切换到gitee_AOSP-RISCV 的开源仓库在 Gitee 上新建了镜像
  7. 杭州软件测试培训有用吗,杭州软件测试培训靠谱吗
  8. 随机名字生成小demo源码
  9. Toad for Oracle 导入MIP.dmp文件时:报内存不足时的解决办法:
  10. C++ 流的操作 | 初识IO类、文件流、string流的使用