如何實作自訂 QR 碼顏色
QR 碼已從簡單的黑白圖案演變為強大的品牌推廣工具。 到了 2025 年,企業已意識到,一個設計精良的 QR 碼不僅能強化品牌識別度,同時也能確保其具備完整的可掃描性。 自訂 QR 碼的前景與背景顏色,可讓您打造視覺上引人注目的設計。
IronQR 使得使用 QrStyleOptions 類別簡單地修改 QR 碼顏色。 您可以變更前景色(深色模組)、背景色,或兩者皆變,以符合您的品牌規範。
在這份操作指南中,我們將逐步介紹如何使用 IronQR 在 C# 中自訂 QR 碼的顏色。
快速入門:自訂 QR 碼顏色透過 QrStyleOptions 設定前景色和彩色背景,並保存樣式化的 QR 碼。
-
1使用 IronQR 安裝 NuGet Package Manager
-
2複製並運行這段程式碼。
var qrCode = QrWriter.Write("https://example.com"); var style = new QrStyleOptions { Color = Color.DarkBlue, BackgroundColor = Color.LightYellow }; qrCode.Save(style).SaveAs("colored-qr.png");Dim qrCode = QrWriter.Write("https://example.com") Dim style = New QrStyleOptions With { .Color = Color.DarkBlue, .BackgroundColor = Color.LightYellow } qrCode.Save(style).SaveAs("colored-qr.png")Dim qrCode = QrWriter.Write("https://example.com") Dim style = New QrStyleOptions With { .Color = Color.DarkBlue, .BackgroundColor = Color.LightYellow } qrCode.Save(style).SaveAs("colored-qr.png") -
3部署到您的生產環境進行測試
立即在您的項目中開始使用 IronQR,並使用 免費試用
最小工作流程(5 個步驟)
- 下載 C# 程式庫以創建具有自訂顏色的QR碼
- 使用
QrWriter類別建立 QR 碼 - 初始化
QrStyleOptions以設定外觀 - 設定
Color和BackgroundColor屬性 - 使用"
SaveAs功能儲存格式化的 QR 碼
變更背景顏色
QR 碼的背景色是指環繞深色模組周圍的淺色區域。 預設顏色為白色,但您可以將其更改為任何與前景形成足夠對比的顏色。
設定自訂背景顏色在將 QR 碼放置於彩色表面時,或當您希望與品牌色系相匹配時,會非常有用。 請確保字體對比度足夠,以便掃描器能可靠地讀取程式碼。
using IronQr;
using IronSoftware.Drawing;
// Create a QR code
QrCode qr = QrWriter.Write("https://ironsoftware.com/csharp/qr/");
// Set background color
QrStyleOptions styleOptions = new QrStyleOptions()
{
BackgroundColor = Color.LightBlue
};
// Save QR code with custom background
AnyBitmap qrImage = qr.Save(styleOptions);
qrImage.SaveAs("qrBackgroundColor.png");using IronQr;
using IronSoftware.Drawing;
// Create a QR code
QrCode qr = QrWriter.Write("https://ironsoftware.com/csharp/qr/");
// Set background color
QrStyleOptions styleOptions = new QrStyleOptions()
{
BackgroundColor = Color.LightBlue
};
// Save QR code with custom background
AnyBitmap qrImage = qr.Save(styleOptions);
qrImage.SaveAs("qrBackgroundColor.png");Imports IronQr
Imports IronSoftware.Drawing
' Create a QR code
Dim qr As QrCode = QrWriter.Write("https://ironsoftware.com/csharp/qr/")
' Set background color
Dim styleOptions As New QrStyleOptions() With {
.BackgroundColor = Color.LightBlue
}
' Save QR code with custom background
Dim qrImage As AnyBitmap = qr.Save(styleOptions)
qrImage.SaveAs("qrBackgroundColor.png")Imports IronQr
Imports IronSoftware.Drawing
' Create a QR code
Dim qr As QrCode = QrWriter.Write("https://ironsoftware.com/csharp/qr/")
' Set background color
Dim styleOptions As New QrStyleOptions() With {
.BackgroundColor = Color.LightBlue
}
' Save QR code with custom background
Dim qrImage As AnyBitmap = qr.Save(styleOptions)
qrImage.SaveAs("qrBackgroundColor.png")
變更前景色
前景色代表 QR 碼的深色模塊 - 掃描器讀取的實際數據模式。 雖然黑色是標準選擇,但您也可以使用任何與背景形成良好對比的深色。
變更前景色可讓您將品牌的主色調融入 QR 碼設計中。 深藍色、深綠色或濃郁的酒紅色都是黑色之外的良好替代色選。
using IronQr;
using IronSoftware.Drawing;
// Create a QR code
QrCode qr = QrWriter.Write("https://ironsoftware.com/csharp/qr/");
// Set background color
QrStyleOptions styleOptions = new QrStyleOptions()
{
Color = Color.PaleVioletRed
};
// Save QR code with custom background
AnyBitmap qrImage = qr.Save(styleOptions);
qrImage.SaveAs("qrBackgroundColor.png");using IronQr;
using IronSoftware.Drawing;
// Create a QR code
QrCode qr = QrWriter.Write("https://ironsoftware.com/csharp/qr/");
// Set background color
QrStyleOptions styleOptions = new QrStyleOptions()
{
Color = Color.PaleVioletRed
};
// Save QR code with custom background
AnyBitmap qrImage = qr.Save(styleOptions);
qrImage.SaveAs("qrBackgroundColor.png");Imports IronQr
Imports IronSoftware.Drawing
' Create a QR code
Dim qr As QrCode = QrWriter.Write("https://ironsoftware.com/csharp/qr/")
' Set background color
Dim styleOptions As New QrStyleOptions() With {
.Color = Color.PaleVioletRed
}
' Save QR code with custom background
Dim qrImage As AnyBitmap = qr.Save(styleOptions)
qrImage.SaveAs("qrBackgroundColor.png")Imports IronQr
Imports IronSoftware.Drawing
' Create a QR code
Dim qr As QrCode = QrWriter.Write("https://ironsoftware.com/csharp/qr/")
' Set background color
Dim styleOptions As New QrStyleOptions() With {
.Color = Color.PaleVioletRed
}
' Save QR code with custom background
Dim qrImage As AnyBitmap = qr.Save(styleOptions)
qrImage.SaveAs("qrBackgroundColor.png")
結論
透過 IronQR 自訂 QR 碼顏色,不僅能激發創意,更能確保您的 QR 碼完全正常運作:
- 背景色: 使用
BackgroundColor來更改 QR 圖案後面的淺色區域 - 前景色: 使用
Color修改編碼您的數據的深色模塊 - 組合樣式: 同時設置這兩個屬性以實現完整的品牌對齊
請務必保持前景與背景色彩之間的適當對比度,以確保在不同裝置及光線條件下皆能清晰辨識。
欲了解更多樣式選擇,包括標誌、邊距和尺寸,請訪問IronQR 文件或探索其他 GitHub 上的程式碼示例。
常見問題
使用IronQR自訂QR碼顏色的目的是什麼?
使用IronQR自訂QR碼顏色可以幫助企業強化品牌識別,創造出視覺吸引且容易辨識的設計,同時保持完全的可掃描性。
如何使用IronQR設定QR碼的前景色和背景色?
您可以使用IronQR中的QrStyleOptions類別設定QR碼的前景色和背景色。初始化QrStyleOptions,並設定Color和BackgroundColor屬性來自訂QR碼的外觀。
為什麼保持QR碼前景色與背景色之間的對比度很重要?
保持前景色與背景色之間足夠的對比度至關重要,以確保在不同設備和光線條件下的可靠掃描。
我可以為QR碼的前景和背景使用任何顏色嗎?
雖然您可以選擇任何顏色作為前景和背景,但選擇具有足夠對比度的顏色以確保QR碼保持可掃描性非常重要。
如何使用IronQR儲存具有自訂顏色的樣式化QR碼?
在使用QrStyleOptions設定所需的顏色後,使用SaveAs方法將具有自訂顏色的樣式化QR碼儲存到文件中。
使用IronQR我可以將QR碼圖片儲存為哪些文件格式?
IronQR允許您將QR碼圖片儲存為各種格式。範例使用的格式為.png。
我可以將生成的QR碼嵌入到不同顏色的表面嗎?
可以,通過自訂背景色以匹配QR碼將放置的表面,您可以增強其整合,同時確保足夠的對比度以便掃描。
IronQR提供哪些額外的QR碼樣式選項?
除了顏色自訂,IronQR還提供添加標誌、調整邊距和更改尺寸的樣式選項。您可以在IronQR文件中找到更多詳情。
IronQR是否相容於C#用於QR碼顏色自訂?
是的,IronQR與C#相容,並提供各種自訂QR碼顏色的選項,可直接在C#專案中使用。
Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。