開源項目QRCoder介紹


簡介

QRCoder是一個簡單的庫,用C#.NET編寫,可讓您創建QR碼。

它與其他庫沒有任何依賴關系,並且可以在NuGet上以.NET Framework和.NET Core PCL版本獲得。

有關更多信息,請參見:QRCode Wiki | 創作者的博客(英語)| 創作者的博客(德語)

QRCoder是Raffael Herrmann的項目,於10/2013首次發布。 它已獲得MIT許可。

 

安裝

簽出此Github存儲庫,或通過NuGet軟件包管理器安裝QRCoder。 如果要使用NuGet,只需搜索“ QRCoder”或在NuGet軟件包管理器控制台中運行以下命令:

PM>安裝包QRCoder
注意:NuGet提要僅包含穩定版本。 如果您不需要最新的版本,則將以下網址之一添加到Visual Studio的NuGet包管理器選項的“包源”中。

NuGet V3提要URL(Visual Studio 2015+):https://www.myget.org/F/qrcoder/api/v3/index.json

NuGet V2提要URL(Visual Studio 2012+):https://www.myget.org/F/qrcoder/api/v2

 

使用

您只需要五行代碼即可生成和查看您的第一個QR碼。

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("The text which should be encoded.", QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);
Bitmap qrCodeImage = qrCode.GetGraphic(20);

 

可選參數和重載

GetGraphics方法具有更多的重載。 前兩個使您可以設置QR碼圖形的顏色。 一種使用Color-class-types,另一種使用HTML十六進制顏色表示法。

//Set color by using Color-class types
Bitmap qrCodeImage = qrCode.GetGraphic(20, Color.DarkRed, Color.PaleGreen, true);

//Set color by using HTML hex color notation
Bitmap qrCodeImage = qrCode.GetGraphic(20, "#000ff0", "#0ff000");

另一個重載使您可以在QR碼的中心渲染徽標/圖像。

Bitmap qrCodeImage = qrCode.GetGraphic(20, Color.Black, Color.White, (Bitmap)Bitmap.FromFile("C:\\myimage.png"));

還有很多其他選擇。 因此,隨時可以在我們的Wiki上閱讀更多內容:Wiki:如何使用QRCoder

 

項目地址:https://github.com/codebude/QRCoder/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM