跳過到頁腳內容
條碼工具

QR碼庫(開發人員指南)

QR Code是一種類似於二維條碼的更多功能選項,且比傳統條碼更小更易於使用。 它經常被用來幫助人們在移動中找到信息或與他們喜愛的品牌建立聯繫。 QR Code由兩個部分組成 - 左半部分和右半部分。 左半部分通常為黑色像素,而右半部分為白色。QR Code是使用專用QR Code掃描儀進行掃描的,藉助於激光技術從白色部分的圖案中以高速捕獲數據,就像那些與信用卡終端一起使用的設備。 QR Code可以用於許多目的,例如顯示商店信息、廣告、促銷、優惠券和新聞文章。 您可能會看到QR Code印在書籍封面前方,但更常見的是在書籍封面後方,或它可能被貼在公告板上。 例如,QR Code技術可以被放置在學校圖書館中以訪問書籍。 QR Code不僅可以幫助學生了解圖書館內容,還可以提供鏈接到無數其他信息的可能性,例如,為學生線上測驗提供鏈接。

QR Code技術有各種使用案例,包括營銷和廣告活動、電子商務網站、銷售點系統、非接觸式支付等。 雖然它們已經存在了一段時間,但最近消費者才開始在日常生活中使用它們。 QR Code在廣告商和消費者中越來越受歡迎。 它們提供了一種無縫的方法來獲取關於商品或服務的快速信息,而不需要輸入地址或電話號碼。 如果您是一名程序員正在製作QR Code圖片,請閱讀本指南以了解其便捷之處。

在本文中,您將了解如何使用不同的語言(例如JavaScript、Python和C#)程式生成和掃描QR Code。 讓我們開始吧。

QuaggaJS:JavaScript函式庫

Qr Code Library 1 related to QuaggaJS:JavaScript函式庫

QuaggaJS是一個用於生成條碼的JavaScript函式庫。 它利用現代瀏覽器功能以使其能在任何平台和瀏覽器中運行。 由於性能快速、可攜性和兼容性優秀,開發人員廣泛使用QuaggaJS。 這個JavaScript函式庫支持多種編碼類型,如UPC-A、UPC-E、Code 128、Code 39、Interleaved 2 of 5 (ITF)和EAN 8/13。不需要下載或安裝任何額外的依賴項即可使用它。 QuaggaJS使開發人員能夠僅用幾行代碼在網頁上生成複雜的條碼類似輸出。 它提供了一個高級API,抽象了所有HTML5畫布和JavaScript API的復雜性,同時提供合理的默認值。

QuaggaJS被那些尋求將QR Code融入設計的開發人員和設計師廣泛使用,以創建數位營銷解決方案。 該函式庫也與許多框架兼容,如React Native、Angular、Vue.js、Ionic 4等。

QuaggaJS庫可以使用NPM命令進行安裝。 以下是使用QuaggaJS庫在專案中的代碼示例:

// Initialize the QuaggaJS library for processing barcodes
Quagga.init({
    inputStream: {
        name: "Live",                // Stream type
        type: "LiveStream",          // Live stream from a webcam
        target: document.querySelector('#yourElement') // Target HTML element for rendering
    },
    decoder: {
        readers: ["code_128_reader"] // Barcode types to decode
    }
}, function(err) {
    if (err) {
        console.log(err);            // Log any initialization errors
        return;
    }
    console.log("Initialization finished. Ready to start");
    Quagga.start();                  // Start processing after initialization
});
// Initialize the QuaggaJS library for processing barcodes
Quagga.init({
    inputStream: {
        name: "Live",                // Stream type
        type: "LiveStream",          // Live stream from a webcam
        target: document.querySelector('#yourElement') // Target HTML element for rendering
    },
    decoder: {
        readers: ["code_128_reader"] // Barcode types to decode
    }
}, function(err) {
    if (err) {
        console.log(err);            // Log any initialization errors
        return;
    }
    console.log("Initialization finished. Ready to start");
    Quagga.start();                  // Start processing after initialization
});
JAVASCRIPT

您可以使用靜態圖像、即時攝像頭或文件API來掃描條碼。

Segno:Python函式庫

Qr Code Library 2 related to Segno:Python函式庫

Segno是用於在Python中讀取、寫入和生成條碼的函式庫。 使用此函式庫,您可以輕鬆從頭開始創建條碼圖片。 Segno使用NumPy數組以高效編碼和解碼條碼。 Segno的語法類似於Python的烏龜模塊之一,所以很容易很快熟練掌握它。 Segno在設計上着重於簡單,使開發人員無需先前的條碼生成知識就可以使用它。 然而,它也有一個強大的API,使得開發人員可以擴展Segno的功能,如果他們想從條碼中獲得更多。

Segno的獨特功能包括根據條碼數據字段以多種方式生成相同條碼圖像; 支持固定大小、可變大小或兩者兼有; 支持高分辨率點陣輸出; 以及帶有工具提示的側邊欄,可以幫助用戶生成圖像。 以下是Segno庫在Python專案中使用的代碼示例:

# Import the Segno library
import segno

# Create a QR code with specified data
qrcode = segno.make('Yellow Submarine')

# Save the generated QR code as a PNG file
qrcode.save('yellow-submarine.png')
# Import the Segno library
import segno

# Create a QR code with specified data
qrcode = segno.make('Yellow Submarine')

# Save the generated QR code as a PNG file
qrcode.save('yellow-submarine.png')
PYTHON

您可以使用PIP安裝來安裝它。

IronBarcode:C#條碼函式庫

Qr Code Library 3 related to IronBarcode:C#條碼函式庫

IronBarcode是一個支持條碼標準函式庫的代碼對象集合。 這包括條碼編碼器、條碼生成器和編輯器等。 它提供了一個易於使用的API,適合移動和Web應用程序。 IronBarcode通過提供標準化的代碼對象庫來減少手動編碼工作,這些對象庫可以在您的應用程序中重複使用。 這些對象通過自動化特定過程和維護您的應用程序來減少開發時間,使其更易於訪問,因為它們在平台間標準化。

IronBarcode是當今增長最快的函式庫之一,原因在於其易於使用和高性能。 由於能夠在iOS、Android和Web瀏覽器上運行而無需任何更改或修改,IronBarcode是您下一個專案的絕佳選擇。 此函式庫提供了一個條碼生成的抽象層,同時提供一組標準工具和代碼片段來簡化開發。 導入此函式庫並傳入生成的代碼以創建條碼是有幫助的。 讓我們看看代碼示例以了解函式庫流程。

代碼示例

using IronBarCode;

//*******     WRITE A QR CODE      *******/

// Create a Barcode in 1 Line of Code
BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.QRCode).SaveAsJpeg("QuickStart.jpg");

//*******    READ A QR CODE    *******/

// Read a Barcode in 1 Line of Code. Gets text, numeric codes, binary data, and an image of the barcode
BarcodeResult result = BarcodeReader.QuicklyReadOneBarcode("QuickStart.jpg");

// Check the result of reading the QR code
if (result != null && result.Text == "https://ironsoftware.com/csharp/barcode")
{
    System.Console.WriteLine("Success!"); // Confirm the text matches
}
using IronBarCode;

//*******     WRITE A QR CODE      *******/

// Create a Barcode in 1 Line of Code
BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.QRCode).SaveAsJpeg("QuickStart.jpg");

//*******    READ A QR CODE    *******/

// Read a Barcode in 1 Line of Code. Gets text, numeric codes, binary data, and an image of the barcode
BarcodeResult result = BarcodeReader.QuicklyReadOneBarcode("QuickStart.jpg");

// Check the result of reading the QR code
if (result != null && result.Text == "https://ironsoftware.com/csharp/barcode")
{
    System.Console.WriteLine("Success!"); // Confirm the text matches
}
$vbLabelText   $csharpLabel

以上代碼是用於使用IronBarcode函式庫創建和讀取QR Code。 這非常簡單易用。 您需要導入庫,寫一些代碼,然後您的條碼就可以準備使用和讀取了。

using IronBarCode;

/*** EXPORTING BARCODES AS HTML FILES OR TAGS ***/

// Create a barcode object
GeneratedBarcode myBarCode = BarcodeWriter.CreateBarcode("1234567890", BarcodeWriterEncoding.Code128);

// Save as a stand-alone HTML file with no image assets required
myBarCode.SaveAsHtmlFile("MyBarCode.html");

// Save as a stand-alone HTML image tag which can be served in HTML files, ASPX, or MVC Views. No image assets required, the tag embeds the entire image in its src contents
string imgTag = myBarCode.ToHtmlTag();

// Turn the image into an HTML/CSS Data URI
string dataURI = myBarCode.ToDataUrl();
using IronBarCode;

/*** EXPORTING BARCODES AS HTML FILES OR TAGS ***/

// Create a barcode object
GeneratedBarcode myBarCode = BarcodeWriter.CreateBarcode("1234567890", BarcodeWriterEncoding.Code128);

// Save as a stand-alone HTML file with no image assets required
myBarCode.SaveAsHtmlFile("MyBarCode.html");

// Save as a stand-alone HTML image tag which can be served in HTML files, ASPX, or MVC Views. No image assets required, the tag embeds the entire image in its src contents
string imgTag = myBarCode.ToHtmlTag();

// Turn the image into an HTML/CSS Data URI
string dataURI = myBarCode.ToDataUrl();
$vbLabelText   $csharpLabel

IronBarcode支持將QR Code匯出為HTML文件或標籤。 它可以匯出在表標籤中。 以上代碼展示了將QR Code轉換為HTML的過程。 您可以從IronBarcode函式庫網站獲取更多詳細信息,使用此連結

授權

IronBarcode在開發階段是免費的。 您可以獲取一個免費試用版以供商業用途或生產級別使用。 IronBarcode有三種定價方案,根據開發人員的需求。 您可以選擇最符合您需求的選項。 您還可以以2款Iron Software產品的價格購買5款Iron Software產品的套裝。 從此連結獲取更多信息。

Jordi Bardia
軟體工程師
Jordi 在 Python、C# 和 C++ 上最得心應手,當他不在 Iron Software 展現技術時,便在做遊戲編程。在分担產品测测试,產品開發和研究的责任時,Jordi 為持续的產品改進增值。他说这种多样化的经验使他受到挑战并保持参与, 而这也是他与 Iron Software 中工作一大乐趣。Jordi 在佛罗里达州迈阿密长大,曾在佛罗里达大学学习计算机科学和统计学。

鋼鐵支援團隊

我們每週 5 天,每天 24 小時在線上。
聊天
電子郵件
打電話給我