.NET C#利用ZXing產生、辨識二維碼/條碼
一、首先下载 ZXing.Net
地址是:http://zxingnet.codeplex.com/releases/view/117068
然后将对应版本 .dll 拖入项目中,再引用之。
主要是用 BarcodeWriter、BarcodeReader。
二、生成二维码
.NET 平台的代码始终要简单些。
QrCodeEncodingOptions options = new QrCodeEncodingOptions(); options.CharacterSet = "UTF-8"; options.DisableECI = true; // Extended Channel Interpretation (ECI) 主要用于特殊的字符集。并不是所有的扫描器都支持这种编码。 options.ErrorCorrection = ZXing.QrCode.Internal.ErrorCorrectionLevel.H; // 纠错级别 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 具备生成、写入两个功能 { MemoryStream ms = new MemoryStream(); { bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png); Response.ContentType = "image/png"; Response.BinaryWrite(ms.ToArray()); } } Response.End();
纠错级别:
L - 约 7% 纠错能力。
M - 约 15% 纠错能力。
Q - 约 25% 纠错能力。
H - 约 30% 纠错能力。
三、生成条形码
QrCodeEncodingOptions options = new QrCodeEncodingOptions(); options.CharacterSet = "UTF-8"; options.Width = 300; options.Height = 50; options.Margin = 1; options.PureBarcode = false; // 是否是纯码,如果为 false,则会在图片下方显示数字 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();
四、识别二维码、条形码
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); }
总结
好了,以上就是这篇文章的全部内容了,如果要改变背景颜色、画头像,可以直接在 Bitmap 中画,希望本文的内容对大家的学习或者工作能带来一定的帮助
更多.NET C#利用ZXing生成、识别二维码/条形码相关文章请关注PHP中文网!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

C#.NET依然重要,因為它提供了強大的工具和庫,支持多種應用開發。 1)C#結合.NET框架,使開發高效便捷。 2)C#的類型安全和垃圾回收機制增強了其優勢。 3).NET提供跨平台運行環境和豐富的API,提升了開發靈活性。

C#.NETisversatileforbothwebanddesktopdevelopment.1)Forweb,useASP.NETfordynamicapplications.2)Fordesktop,employWindowsFormsorWPFforrichinterfaces.3)UseXamarinforcross-platformdevelopment,enablingcodesharingacrossWindows,macOS,Linux,andmobiledevices.

C#在企業級應用、遊戲開發、移動應用和Web開發中均有廣泛應用。 1)在企業級應用中,C#常用於ASP.NETCore開發WebAPI。 2)在遊戲開發中,C#與Unity引擎結合,實現角色控制等功能。 3)C#支持多態性和異步編程,提高代碼靈活性和應用性能。

c#.netissutableforenterprise-levelapplications withemofrosoftecosystemdueToItsStrongTyping,richlibraries,androbustperraries,androbustperformance.however,itmaynotbeidealfoross-platement forment forment forment forvepentment offependment dovelopment toveloperment toveloperment whenrawspeedsportor whenrawspeedseedpolitical politionalitable,

C#和.NET通過不斷的更新和優化,適應了新興技術的需求。 1)C#9.0和.NET5引入了記錄類型和性能優化。 2).NETCore增強了雲原生和容器化支持。 3)ASP.NETCore與現代Web技術集成。 4)ML.NET支持機器學習和人工智能。 5)異步編程和最佳實踐提升了性能。

C#在.NET中的編程過程包括以下步驟:1)編寫C#代碼,2)編譯為中間語言(IL),3)由.NET運行時(CLR)執行。 C#在.NET中的優勢在於其現代化語法、強大的類型系統和與.NET框架的緊密集成,適用於從桌面應用到Web服務的各種開發場景。

如何將C#.NET應用部署到Azure或AWS?答案是使用AzureAppService和AWSElasticBeanstalk。 1.在Azure上,使用AzureAppService和AzurePipelines自動化部署。 2.在AWS上,使用AmazonElasticBeanstalk和AWSLambda實現部署和無服務器計算。

C#和.NET運行時緊密合作,賦予開發者高效、強大且跨平台的開發能力。 1)C#是一種類型安全且面向對象的編程語言,旨在與.NET框架無縫集成。 2).NET運行時管理C#代碼的執行,提供垃圾回收、類型安全等服務,確保高效和跨平台運行。
