zxing .net 多種條碼格式的生成

下載地址: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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/454394.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/454394.shtml
英文地址,請注明出處:http://en.pswp.cn/news/454394.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

k8s dashboard_windows10 部署 docker+k8s 集群

下面是經過踩坑之后的 windows10 單機部署 docker k8s 步驟,其中有幾處比較關鍵的地方需要注意,后面加粗標注,下面就開始吧!0、下載cmder在 windows 上有一個趁手的命令行工具非常有必要,推薦 Cmder,下面是…

Python 之網絡編程基礎

套接字(socket)初使用 基于TCP協議的socket tcp是基于鏈接的,必須先啟動服務端,然后再啟動客戶端去鏈接服務端 server端 import socket sk socket.socket() sk.bind((127.0.0.1,8898)) # 把地址綁定到套接字 sk.listen() …

ajax on ture,細數Ajax請求中的async:false和async:true的差異

實例如下:function test(){var temp"00";$.ajax({async: false,type : "GET",url : userL_checkPhone.do,complete: function(msg){alert(complete);},success : function(data) {alert(success);tempdata;temp"aa";}});alert(temp);…

阿里云郵箱登錄日志中有異地IP登錄是怎么回事?該怎么辦?

注意,請先到阿里云官網 領取幸運券,除了價格上有很多優惠外,還可以參與抽獎。詳見:https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode2a7uv47d&utm_source2a7uv47d以下可能:1、您的郵…

面試之網絡編程和并發

1、簡述 OSI 七層協議。 物理層:主要基于電器特性發送高低電壓(1、0),設備有集線器、中繼器、雙絞線等,單位:bit 數據鏈路層:定義了電信號的分組方式,設備:交換機、網卡、網橋,單位&…

redis 遠程主機強迫關閉了一個現有的連接_記一次Redis+Getshell經驗分享

你是我患得患失的夢,我是你可有可無的人,畢竟這穿越山河的箭,刺的都是用情之疾的人。前言:當我們接到一個授權滲透測試的時候,常規漏洞如注入、文件上傳等嘗試無果后,掃描端口可能會發現意外收獲。知己知彼…

無線連接 服務器,服務器無線遠程連接

服務器無線遠程連接 內容精選換一換華為云幫助中心,為用戶提供產品簡介、價格說明、購買指南、用戶指南、API參考、最佳實踐、常見問題、視頻幫助等技術文檔,幫助您快速上手使用華為云服務。使用Mac版Microsoft Remote Desktop工具,遠程連接W…

面試前您該做的事情

選自本人作品:《軟件性能測試與LR實戰》 無論您是剛剛畢業的大學生朋友,還是已經有工作經驗的同行,大家都不可避免的面臨一個問題就是找工作或者換工作的問題。在整個應聘過程中,面試無疑是最具有決定性意義的重要環節&#xff0c…

IO模型

IO模型介紹 傳統的網絡IO模型包括五種: blocking IO 阻塞IOnonblocking IO 非阻塞IOIO multiplexing IO多路復用signal driven IO 信號驅動IOasynchronous IO 異步IO 由于signal driven IO(信號驅動IO)在實際中…

重溫數據結構:樹 及 Java 實現(轉)

轉自:http://blog.csdn.net/u011240877/article/details/53193877 讀完本文你將了解到: 什么是樹樹的相關術語 根節點父親節點孩子節點葉子節點如上所述節點的度樹的度節點的層次樹的高度樹的深度樹的兩種實現 數組表示鏈表表示的節點樹的幾種常見分類及…

Powershell檢測AD賬戶密碼過期時間并郵件通知

腳本主要實現了兩個功能 : 一能判斷賬戶密碼的過期時間并通過郵件通知到賬戶; 二是將這些即將過期的賬戶信息累計通知到管理員。 腳本如下: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051…

js list刪除指定元素_vue.js

vue.js 中M V MV代表哪一部分 <插值表達式&#xff08;v-cloak v-text v-html v-bind&#xff08;縮寫是:&#xff09; v-on&#xff08;縮寫是&#xff09; v-model v-for v-if v-show &#xff09;<body><div id"app"><!-- 使用 v-cloak 能夠解決…

修改db2管理服務器,創建DB2管理服務器的兩種情況

DB2管理服務器在創建時分為創建一個和創建多個兩種情況&#xff0c;下面就為您詳細介紹這兩種創建DB2管理服務器的情況&#xff0c;供您參考學習。一、創建DB2管理服務器(只能創建一個)1、首先創建管理服務組用戶(可不建)命令&#xff1a;sudo groupadd dasadm12、創建用戶命令…

系統程序員成長計劃-走近專業程序員

轉載時請注明出處和作者聯系方式 文章出處&#xff1a;http://www.limodev.cn/blog 作者聯系方式&#xff1a;李先靜 <xianjimli at hotmail dot com> 需求簡述 用C語言編寫一個雙向鏈表。如果你有一定的C語言編程經驗&#xff0c;這自然是小菜一碟。有的讀者可能連一個…

Python 內置模塊之 asyncio(異步iO)

python3.0&#xff0c;標準庫里的異步網絡模塊&#xff1a;select(非常底層) &#xff0c;第三方異步網絡庫&#xff1a;Tornado&#xff0c;gevent python3.4&#xff0c;asyncio&#xff1a;支持 TCP &#xff0c;子進程 現在的asyncio&#xff0c;有了很多的模塊已經在支持…

前端js文件合并三種方式

最近在思考前端js文件該如何合并&#xff0c;當然不包括不能合并文件&#xff0c;而是我們能合并的文件&#xff0c;想了想應該也只有三種方式。 三個方式如下&#xff1a; 1. 一個大文件&#xff0c;所有js合并成一個大文件&#xff0c;所有頁面都引用它。 2. 各個頁面大文件&…

我們的系統檢測到您的計算機網絡中存在異常流量_如何建立我們的網絡防線?入侵檢測,確保我們的網絡安全...

目前我們的網絡安全趨勢日益嚴峻&#xff0c;那么如何利用入侵檢測系統確保我的網絡安全呢&#xff1f;入侵檢測又是什么呢&#xff1f;網絡安全入侵檢測技術是為保證計算機系統的安全&#xff0c;而設計與配置的一種能夠及時發現并報告系統中未授權或異常現象的技術&#xff0…

sql修改鏈接服務器名稱,SQL Server 創建鏈接服務器的腳本,自定義鏈路服務器的簡短名稱...

USE [master]GO/****** Object: LinkedServer [SQL01] Script Date: 2020/4/9 11:51:17 ******/EXEC master.dbo.sp_addlinkedserver server N‘SQL01‘, srvproductN‘‘, providerN‘SQLNCLI‘, datasrcN‘域名或者IP‘/* For security reasons the linked server remot…

mybatis $和#源代碼分析

JDBC中&#xff0c;主要使用兩種語句&#xff0c;一種是支持參數化和預編譯的PreparedStatement,支持原生sql,支持設置占位符&#xff0c;參數化輸入的參數&#xff0c;防止sql注入攻擊&#xff0c;在mybatis的mapper配置文件中&#xff0c;我們通過使用#和$告訴mybatis我們需要…

git 命令詳解和常見問題解決

功能一 提交&#xff1a;1:git init # 初始化&#xff0c;表示即將對當前文件夾進行版本控制2:git status # 查看Git當前狀態&#xff0c;如&#xff1a;那些文件被修改過、那些文件還未提交到版本庫等。3:git add . # 添加當前目錄下所有文件到版本…