using IronBarCode;
// The value of the QR code as a string. Also suitable for URLS
string value = "https://ironsoftware.com/";
// Simplest example of creating a QR Code with no settings
GeneratedBarcode myQRCode = QRCodeWriter.CreateQrCode(value);
// Advanced example with all parameters exclusive to QR codes set:
// The error correction level of the QR code
var correction = QRCodeWriter.QrErrorCorrectionLevel.Highest;
// The width and height of the QR code in pixels
int size = 500;
// QR version.
// Please read https://www.qrcode.com/en/about/version.html to learn more about what QR version is
int qrVersion = 0;
GeneratedBarcode myQRCodeComplex = QRCodeWriter.CreateQrCode(value, size, correction, qrVersion);
Imports IronBarCode
' The value of the QR code as a string. Also suitable for URLS
Private value As String = "https://ironsoftware.com/"
' Simplest example of creating a QR Code with no settings
Private myQRCode As GeneratedBarcode = QRCodeWriter.CreateQrCode(value)
' Advanced example with all parameters exclusive to QR codes set:
' The error correction level of the QR code
Private correction = QRCodeWriter.QrErrorCorrectionLevel.Highest
' The width and height of the QR code in pixels
Private size As Integer = 500
' QR version.
' Please read https://www.qrcode.com/en/about/version.html to learn more about what QR version is
Private qrVersion As Integer = 0
Private myQRCodeComplex As GeneratedBarcode = QRCodeWriter.CreateQrCode(value, size, correction, qrVersion)
Install-Package BarCode
創建QR碼
IronBarcode 為開發者提供直觀且易於使用的方法,可建立具備豐富自訂選項的獨特 QR 碼。 無論您是尋求僅需幾行程式碼即可運作的簡易 QR 碼產生器,還是需要能全面控制 QR 碼各項參數(例如糾錯等級、尺寸及版本)的進階產生器,IronBarcode 都能透過單一程式庫滿足您的所有需求。
在導入 IronBarcode 函式庫後,我們首先建立 QRCodeWriter 類別的實例,接著使用 QRCodeWriter.CreateQrCode 來建立一個新的 QR 碼,其字串值為一個 URL。 此方法是使用預設設定建立 QR 碼的最簡單方式。
我們可調整 QR 碼中的 errorCorrectionLevel 以進行更多客製化。 此等級與 QR 碼中包含的冗餘或錯誤復原資料量相關,使其更具容錯性,並確保能在嚴苛環境下正常運作。
若要控制 size,只需為其賦予一個整數值即可。 qrVersion(數字介於 1 至 40 之間)代表 QR 碼的版本。 開發人員可根據欲儲存的資料量及 QR 碼所需的容量,進行微調以在容量與大小之間取得平衡,確保最佳化效果。 如需進一步了解如何確認您的 QR 碼版本,請參閱此處的文件。
最後,我們將所有已建立的變數 qrVersion 及 correction 再次傳遞給 QRCodeWriter.CreateQrCode 方法,以產生包含上述所有屬性的客製化 QR 碼。