在生產環境中測試,無水印。
在任何需要的地方都能運行。
獲得 30 天的全功能產品。
在幾分鐘內上手運行。
試用產品期間完全訪問我們的支援工程團隊
QR Code,或稱快速回應碼,已演變為儲存和檢索資訊的多功能格式。 在各個領域中廣泛使用,從行銷到產品標籤,QR Code 圖像提供了一種通過簡單掃描圖片框快速且高效地獲取資訊的方法。
在本文中,我們將探索如何在控制台應用程式中使用IronQR庫生成VB.NET QR Code條碼。
IronQR,是一個強大的 C# 快速響應代碼系統庫,並擴展其對 VB.NET 開發者的支持,用於生成和閱讀 QR Code 條碼。 儘管 IronQR 主要是為 C# 設計,但它與 VB.NET 無縫整合,因為它是基於 .NET Framework 構建,提供了一種方便的方式,易於使用 VB.NET 生成 QR Code 條碼。 其簡單性和豐富的功能集使其成為開發人員尋求高效 VB.NET QR Code 條碼生成解決方案的理想選擇。
在深入研究使用 VB.NET 創建 QR Code 的編碼過程之前,請確保您擁有所需的工具:
Visual Studio: 確保您的系統上已安裝 Visual Studio。 如果不是,請從官方網站下載。
PM > Install-Package IronQR
此命令會安裝在您的VB.NET專案中使用IronQR所需的套件。
首先,讓我們設定一個簡單的 VB.NET 主控台應用程式:
打開 Visual Studio,選擇「建立新專案」。
選擇「主控台應用程式」作為專案範本,然後點擊「下一步」。
配置專案設定,然後點擊「下一步」。
在其他資訊中,選擇最新的 .NET 框架。
在專案設定完成後,點擊「方案總管」,選擇「管理解決方案的 NuGet 套件」。
在 NuGet 視窗中,點擊「瀏覽」標籤並搜尋 IronQR,然後點擊「安裝」按鈕。
在此 QR 碼生成應用程式中,我們將展示使用 IronQR 庫在 (Visual Basic) VB.NET 主控台應用程式中生成 QR 碼的簡單性和靈活性。 我們首先採用最簡單的方法,創建 QR 代碼,使用默認配置。 然後,我們進入更高級的 QR Code 示例,自定義參數如 QR Code 的內容、標誌、大小和版本。 如需更多代碼範例,請訪問QR code generator for .NET。
讓我們來探索以下範例代碼片段,並了解IronBarcode如何在Visual Basic中簡化QR碼和條碼圖像生成。
Imports IronQr
Imports IronSoftware.Drawing
Imports Color = IronSoftware.Drawing.Color
Module Program
' Simplest example of creating a QR Code with no settings:
Private myQrCode As QrCode = QrWriter.Write("https://ironsoftware.com/")
' Save QR Code as a Bitmap
Private qrImage As AnyBitmap = myQrCode.Save()
' Advanced Example to set all parameters:
' The value of the QR Code as a string. Also suitable for URLS.
Private value As String = "https://ironsoftware.com/"
' Set QR options
Private options As New QrOptions(QrErrorCorrectionLevel.High, 20)
' Create a QR Code object
Private myQr As QrCode = QrWriter.Write(value, options)
' Fancy style options
Private logoBmp As New AnyBitmap("VisualStudioLogo.png")
Private style As New QrStyleOptions With {
.Dimensions = 300,
.Margins = 10,
.Color = Color.Gray,
.Logo = New QrLogo With {
.Bitmap = logoBmp,
.Width = 100,
.Height = 100,
.CornerRadius = 2
}
}
' Save QR Code as a Bitmap
Private qrImageComplex As AnyBitmap = myQr.Save(style)
Sub Main(args As String())
IronQR.License.LicenseKey = "IronQR-MYLICENSE-KEY-1EF01"
qrImageSimple.SaveAs("simpleQRCode.png")
qrImageComplex.SaveAs("complexQRCode.png")
End Sub
End Module
Imports IronQr
Imports IronSoftware.Drawing
Imports Color = IronSoftware.Drawing.Color
Module Program
' Simplest example of creating a QR Code with no settings:
Private myQrCode As QrCode = QrWriter.Write("https://ironsoftware.com/")
' Save QR Code as a Bitmap
Private qrImage As AnyBitmap = myQrCode.Save()
' Advanced Example to set all parameters:
' The value of the QR Code as a string. Also suitable for URLS.
Private value As String = "https://ironsoftware.com/"
' Set QR options
Private options As New QrOptions(QrErrorCorrectionLevel.High, 20)
' Create a QR Code object
Private myQr As QrCode = QrWriter.Write(value, options)
' Fancy style options
Private logoBmp As New AnyBitmap("VisualStudioLogo.png")
Private style As New QrStyleOptions With {
.Dimensions = 300,
.Margins = 10,
.Color = Color.Gray,
.Logo = New QrLogo With {
.Bitmap = logoBmp,
.Width = 100,
.Height = 100,
.CornerRadius = 2
}
}
' Save QR Code as a Bitmap
Private qrImageComplex As AnyBitmap = myQr.Save(style)
Sub Main(args As String())
IronQR.License.LicenseKey = "IronQR-MYLICENSE-KEY-1EF01"
qrImageSimple.SaveAs("simpleQRCode.png")
qrImageComplex.SaveAs("complexQRCode.png")
End Sub
End Module
讓我們逐步解析以上用於創建 QR Code 圖像的源代碼:
Imports IronQr
Imports IronSoftware.Drawing
Imports Color = IronSoftware.Drawing.Color
Imports IronQr
Imports IronSoftware.Drawing
Imports Color = IronSoftware.Drawing.Color
以下程式碼行從 IronQR 庫匯入必要的命名空間,提供 QR 碼生成和樣式設置所需的類和方法的訪問權限。
Module Program
Module Program
Module 關鍵字聲明了一個名為「Program」的模組,封裝了代碼。 模組是用於在 VB.NET 中組織代碼的容器。
' Simplest example of creating a QR Code with no settings:
Private myQrCode As QrCode = QrWriter.Write("https://ironsoftware.com/")
' Save QR Code as a Bitmap
Private qrImage As AnyBitmap = myQrCode.Save()
' Simplest example of creating a QR Code with no settings:
Private myQrCode As QrCode = QrWriter.Write("https://ironsoftware.com/")
' Save QR Code as a Bitmap
Private qrImage As AnyBitmap = myQrCode.Save()
在此,使用 QrWriter.Write 方法和 URL ("https://ironsoftware.com/") 創建了一個簡單的 QR 碼。 結果儲存在 myQrCode 變數中。 然後此位元組資料結果被儲存為 AnyBitmap 圖像,以便稍後儲存為 PNG、JPG 圖像格式。
' The value of the QR code as a string. Also suitable for URLS.
Private value As String = "https://ironsoftware.com/"
' Set QR options
Private options As New QrOptions(QrErrorCorrectionLevel.High, 20)
' Create a QR Code object
Private myQr As QrCode = QrWriter.Write(value, options)
' Fancy style options
Private logoBmp As New AnyBitmap("VisualStudioLogo.png")
Private style As New QrStyleOptions With {
.Dimensions = 300,
.Margins = 10,
.Color = Color.Gray,
.Logo = New QrLogo With {
.Bitmap = logoBmp,
.Width = 100,
.Height = 100,
.CornerRadius = 2
}
}
' Save QR Code as a Bitmap
Private qrImageComplex As AnyBitmap = myQr.Save(style)
' The value of the QR code as a string. Also suitable for URLS.
Private value As String = "https://ironsoftware.com/"
' Set QR options
Private options As New QrOptions(QrErrorCorrectionLevel.High, 20)
' Create a QR Code object
Private myQr As QrCode = QrWriter.Write(value, options)
' Fancy style options
Private logoBmp As New AnyBitmap("VisualStudioLogo.png")
Private style As New QrStyleOptions With {
.Dimensions = 300,
.Margins = 10,
.Color = Color.Gray,
.Logo = New QrLogo With {
.Bitmap = logoBmp,
.Width = 100,
.Height = 100,
.CornerRadius = 2
}
}
' Save QR Code as a Bitmap
Private qrImageComplex As AnyBitmap = myQr.Save(style)
在此進階範例程式碼中,我們宣告變數來自訂 QR Code。 在這裡,value包含了QR碼的內容,接著我們使用QrOptions類別設置QrErrorCorrectionLevel。 然後將值和選項傳遞給QrWriter.Write以生成QR碼。 logoBmp 保存 QR 代碼的標誌圖像,style 定義其尺寸、邊距、顏色以及標誌的寬度、高度和圓角。 最後,影像以AnyBitmap的樣式儲存,之後再以PNG、JPG影像格式儲存。
Sub Main(args As String())
IronQR.License.LicenseKey = "IronQR-MYLICENSE-KEY-1EF01"
qrImageSimple.SaveAs("simpleQRCode.png")
qrImageComplex.SaveAs("complexQRCode.png")
End Sub
Sub Main(args As String())
IronQR.License.LicenseKey = "IronQR-MYLICENSE-KEY-1EF01"
qrImageSimple.SaveAs("simpleQRCode.png")
qrImageComplex.SaveAs("complexQRCode.png")
End Sub
在 VB.NET 主控台應用程式中,Main 方法是進入點。 設定您的授權金鑰以移除生成的 QR 碼標誌上的浮水印。 它分別在 qrImageSimple 和 qrImageComplex 上調用 SaveAs 方法,以將生成的 QR 碼保存為圖像文件("simpleQRCode.png" 和 "complexQRCode.png")。
執行主控台應用程式,您應該會看到一條成功訊息,表明 QR Code 已經成功生成並儲存。
簡單 QR Code 圖像的輸出:
複雜 QR 碼圖像的輸出:
本文展示了如何在控制台應用程式中使用 VB.NET 和 IronQR 庫生成 QR 碼。 通過遵循所列步驟,開發人員可以輕鬆地將 QR Code 生成整合到他們的 VB.NET 專案中,為各種應用提供快速且有效的編碼方式。 探索 IronQR 的文檔以獲取更多自定義選項和功能。
IronQR 是一個專精於 QR 碼操作的多功能 .NET 庫。 它能生成 QR Code,支持樣式變化,並識別各種 QR Code 格式和類型。該庫在通過 SaveAsImage() 方法將 QR Code 保存為 JPEG、PNG、BMP、TIFF 和 GIF 等圖像格式方面表現出色,有利於無縫集成和儲存。
出於開發目的,IronQR 可免費使用,但會帶有浮水印。 商業使用需要授權,用戶才能評估其完整功能。