.NET C#利用ZXing生成、識(shí)別二維碼/條形碼
一、首先下載 ZXing.Net
地址是:http://zxingnet.codeplex.com/releases/view/117068
然后將對(duì)應(yīng)版本 .dll 拖入項(xiàng)目中,再引用之。
主要是用 BarcodeWriter、BarcodeReader。
二、生成二維碼
.NET 平臺(tái)的代碼始終要簡(jiǎn)單些。
QrCodeEncodingOptions options = new QrCodeEncodingOptions(); options.CharacterSet = "UTF-8"; options.DisableECI = true; // Extended Channel Interpretation (ECI) 主要用于特殊的字符集。并不是所有的掃描器都支持這種編碼。 options.ErrorCorrection = ZXing.QrCode.Internal.ErrorCorrectionLevel.H; // 糾錯(cuò)級(jí)別 options.Width = 300; options.Height = 300; options.Margin = 1; // options.Hints,更多屬性,也可以在這里添加。 BarcodeWriter writer = new BarcodeWriter(); writer.Format = BarcodeFormat.QR_CODE; writer.Options = options; Response.Clear(); using (Bitmap bmp = writer.Write("http://www.cftea.com")) // Write 具備生成、寫入兩個(gè)功能 { MemoryStream ms = new MemoryStream(); { bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png); Response.ContentType = "image/png"; Response.BinaryWrite(ms.ToArray()); } } Response.End();
糾錯(cuò)級(jí)別:
- L - 約 7% 糾錯(cuò)能力。
- M - 約 15% 糾錯(cuò)能力。
- Q - 約 25% 糾錯(cuò)能力。
- H - 約 30% 糾錯(cuò)能力。
三、生成條形碼
QrCodeEncodingOptions options = new QrCodeEncodingOptions(); options.CharacterSet = "UTF-8"; options.Width = 300; options.Height = 50; options.Margin = 1; options.PureBarcode = false; // 是否是純碼,如果為 false,則會(huì)在圖片下方顯示數(shù)字 BarcodeWriter writer = new BarcodeWriter(); writer.Format = BarcodeFormat.CODE_128; writer.Options = options; Response.Clear(); using (Bitmap bmp = writer.Write("12345678")) { MemoryStream ms = new MemoryStream(); { bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png); Response.ContentType = "image/png"; Response.BinaryWrite(ms.ToArray()); } } Response.End();
四、識(shí)別二維碼、條形碼
BarcodeReader reader = new BarcodeReader(); reader.Options.CharacterSet = "UTF-8"; using (Bitmap bmp = new Bitmap("D:\\qr.png")) { Result result = reader.Decode(bmp); Response.Write(result.Text); }
總結(jié)
好了,以上就是這篇文章的全部?jī)?nèi)容了,如果要改變背景顏色、畫頭像,可以直接在 Bitmap 中畫,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助
欄 目:C#教程
下一篇:淺析C#中文件路徑的操作
本文標(biāo)題:.NET C#利用ZXing生成、識(shí)別二維碼/條形碼
本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/6106.html
您可能感興趣的文章
- 01-10.net2.0+ Winform項(xiàng)目實(shí)現(xiàn)彈出容器層
- 01-10asp.net中XML如何做增刪改查操作
- 01-10C#利用反射技術(shù)實(shí)現(xiàn)去掉按鈕選中時(shí)的邊框效果
- 01-10C#使用ADO.Net部件來(lái)訪問(wèn)Access數(shù)據(jù)庫(kù)的方法
- 01-10時(shí)間戳與時(shí)間相互轉(zhuǎn)換(php .net精確到毫秒)
- 01-10C#.NET實(shí)現(xiàn)網(wǎng)頁(yè)自動(dòng)登錄的方法
- 01-10C#裝箱和拆箱原理詳解
- 01-10實(shí)現(xiàn)ASP.NET無(wú)刷新下載并提示下載完成的開發(fā)思路
- 01-10C#圖片處理3種高級(jí)應(yīng)用
- 01-10C#.NET中如何批量插入大量數(shù)據(jù)到數(shù)據(jù)庫(kù)中


閱讀排行
- 1C語(yǔ)言 while語(yǔ)句的用法詳解
- 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹的示例代碼(圣誕
- 3利用C語(yǔ)言實(shí)現(xiàn)“百馬百擔(dān)”問(wèn)題方法
- 4C語(yǔ)言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
- 5c語(yǔ)言計(jì)算三角形面積代碼
- 6什么是 WSH(腳本宿主)的詳細(xì)解釋
- 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
- 8正則表達(dá)式匹配各種特殊字符
- 9C語(yǔ)言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
- 10C語(yǔ)言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
本欄相關(guān)
- 01-10C#通過(guò)反射獲取當(dāng)前工程中所有窗體并
- 01-10關(guān)于ASP網(wǎng)頁(yè)無(wú)法打開的解決方案
- 01-10WinForm限制窗體不能移到屏幕外的方法
- 01-10WinForm繪制圓角的方法
- 01-10C#實(shí)現(xiàn)txt定位指定行完整實(shí)例
- 01-10WinForm實(shí)現(xiàn)仿視頻 器左下角滾動(dòng)新
- 01-10C#停止線程的方法
- 01-10C#實(shí)現(xiàn)清空回收站的方法
- 01-10C#通過(guò)重寫Panel改變邊框顏色與寬度的
- 01-10C#實(shí)現(xiàn)讀取注冊(cè)表監(jiān)控當(dāng)前操作系統(tǒng)已
隨機(jī)閱讀
- 01-10delphi制作wav文件的方法
- 01-10C#中split用法實(shí)例總結(jié)
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
- 04-02jquery與jsp,用jquery
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
- 01-10使用C語(yǔ)言求解撲克牌的順子及n個(gè)骰子
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 01-11ajax實(shí)現(xiàn)頁(yè)面的局部加載