條碼工具

QR Code Library(開發人員指南)

發佈 2022年5月10日
分享:

QR碼是一種2D條碼,比傳統條碼更小、更易於接觸。它通常用來幫助人們隨時隨地找到信息或連接他們喜愛的品牌。QR碼由兩部分組成 - 左半部和右半部。左半部通常有黑色像素,而右半部是白色的。用手機或電腦上的專用QR碼掃描器掃描QR碼,它會以高速度使用雷射技術捕捉編碼在白色部分的數據圖案,就像信用卡終端使用的一樣。QR碼可以用於多種用途,例如顯示有關商店的信息、廣告、促銷、優惠券和新聞文章。你可能會看到QR碼印在書的封面上,但更多常見的是在書的封底,或者QR碼可能被刻在佈告欄上。QR碼技術可以放置在例如學校圖書館中,用來訪問書籍內容。QR碼不僅可以幫助學生了解圖書館內容,還可以提供無限量的額外信息鏈接,例如,給學生的在線測驗。

QR碼技術有各種使用情境,包括行銷和廣告活動、電子商務網站、點銷系統、非接觸式支付等等。雖然它們已經出現相當長一段時間了,但直到最近消費者才開始在日常生活中使用它們。QR碼在廣告商和消費者中越來越受歡迎。它們提供了一種無需輸入地址或電話號碼即可快速獲取商品或服務信息的無縫方式。如果你是一名製作QR碼圖像的程式設計師,請閱讀這個指南,了解它是多麼簡單。

在本文中,你將看到如何使用JavaScript、Python和C#等不同語言以編程方式掃描和創建QR碼。讓我們開始吧。

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 canvas和JavaScript API的所有複雜性,同時提供了合理的默認值。

QuaggaJS已被廣泛用於希望將QR碼整合到設計中的開發人員和設計師,創建數字營銷解決方案。該庫還兼容許多框架,如React Native、Angular、Vue.js、Ionic 4等。

可以使用NPM命令安裝QuaggaJS庫。以下是項目中使用QuaggaJS庫的代碼示例。

Quagga.init({
    inputStream : {
      name : "Live",
      type : "LiveStream",
      target: document.querySelector('#yourElement')    // Or '#yourElement' (optional)
    },
    decoder : {
      readers : ["code_128_reader"]
    }
  }, function(err) {
      if (err) {
          console.log(err);
          return
      }
      console.log("Initialization finished. Ready to start");
      Quagga.start();
  });
Quagga.init({
    inputStream : {
      name : "Live",
      type : "LiveStream",
      target: document.querySelector('#yourElement')    // Or '#yourElement' (optional)
    },
    decoder : {
      readers : ["code_128_reader"]
    }
  }, function(err) {
      if (err) {
          console.log(err);
          return
      }
      console.log("Initialization finished. Ready to start");
      Quagga.start();
  });
Quagga.init({ inputStream := { name := "Live", type := "LiveStream", target:= document.querySelector( '#yourElement') }, decoder : { readers : ["code_128_reader"] } }, @function(err) { if(err) { console.log(err); Return } console.log("Initialization finished. Ready to start"); Quagga.start(); });
VB   C#

您可以使用靜態圖片、即時網絡攝影機或檔案 API 掃描條碼。

Segno:Python 庫

Segno 是一個用於在 Python 中讀取、編寫和生成條形碼的庫。使用這個庫,您可以輕鬆從頭創建條形碼圖像。Segno 使用 NumPy 陣列來高效地編碼和解碼條形碼。Segno 的語法類似於 Python 的 turtle 模塊之一,因此應該可以很快熟練掌握。Segno 的設計理念是簡單性,使開發者在沒有條形碼生成知識的情況下也能使用它。然而,它也有一個強大的 API,方便開發者擴展 Segno 的功能,從而獲得更多條形碼的應用。

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

import segno
qrcode = segno.make('Yellow Submarine')
qrcode.save('yellow-submarine.png')
import segno
qrcode = segno.make('Yellow Submarine')
qrcode.save('yellow-submarine.png')
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'import segno qrcode = segno.make('Yellow Submarine') qrcode.save('yellow-submarine.png')
VB   C#

你可以使用 PIP 安裝它。

IronBarcode:C# 條碼庫

IronBarcode 是支持條碼標準庫的一組代碼對象。這包括條碼編碼器、條碼生成器和編輯器等。它提供了一個易於使用的 API,適用於移動應用程序和網頁應用程序。IronBarcode 通過提供標準化的代碼對象庫來減少手動編碼工作,這些對象可以在整個應用程序中重複使用。這些對象減少了開發時間,通過自動化特定過程並保持應用程序的可訪問性,因為它們在各平台間都是標準化的。

IronBarcode 是當今增長最快的庫之一,因其易用性和高性能能力而備受青睞。它無需任何更改或修改即可在 iOS、Android 和網頁瀏覽器上運行,使其成為您下一個項目的絕佳選擇。這個庫提供了一個條碼生成的抽象層,同時提供了一組標準工具和代碼片段來簡化開發。引入這個庫並將生成的代碼傳遞給創建條碼的方法非常有幫助。我們來看看代碼示例以了解庫的操作。

範例程式碼

using IronBarCode;

/******     WRITE     *******/

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

/******    READ    *******/

// 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");

// Assert that IronBarCode Works :-)
if (Result!=null && Result.Text == "https://ironsoftware.com/csharp/barcode")
{
    System.Console.WriteLine("Success");
}
using IronBarCode;

/******     WRITE     *******/

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

/******    READ    *******/

// 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");

// Assert that IronBarCode Works :-)
if (Result!=null && Result.Text == "https://ironsoftware.com/csharp/barcode")
{
    System.Console.WriteLine("Success");
}
Imports IronBarCode

'''****     WRITE     ******

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

'''****    READ    ******

' Read A Barcode in 1 Line of Code.  Gets Text, Numeric Codes,  binary Data, and an Image of the barcode
Dim Result As BarcodeResult = BarcodeReader.QuicklyReadOneBarcode("QuickStart.jpg")

' Assert that IronBarCode Works :-)
If Result IsNot Nothing AndAlso Result.Text = "https://ironsoftware.com/csharp/barcode" Then
	System.Console.WriteLine("Success")
End If
VB   C#

以上程式碼是使用 IronBarcode 庫創建和讀取 QR 碼。使用起來非常簡單。您只需導入庫並編寫幾行程式碼,您的條形碼就可以使用和讀取了。

using IronBarCode;

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

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.  https://en.wikipedia.org/wiki/Data_URI_scheme
string DataURI = MyBarCode.ToDataUrl();
using IronBarCode;

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

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.  https://en.wikipedia.org/wiki/Data_URI_scheme
string DataURI = MyBarCode.ToDataUrl();
Imports IronBarCode

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

Private MyBarCode As GeneratedBarcode = 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
Dim ImgTag As String = MyBarCode.ToHtmlTag()

' Turn the image into an Html/CSS Data URI.  https://en.wikipedia.org/wiki/Data_URI_scheme
Dim DataURI As String = MyBarCode.ToDataUrl()
VB   C#

IronBarcode 支援導出 QR 碼至 HTML 檔案或標籤。它可以在表格標籤中導出。上述代碼演示了 QR 碼到 HTML 的轉換。您可以從 IronBarcode 庫網站獲取更多詳細信息使用此 連結.

授權

IronBarcode在開發階段是免費的。您可以獲得 免費試用 適用於商業用途或生產級別。IronBarcode 根據開發者的需求提供三種定價方案。您可以選擇最適合您需求的選項。您還可以以兩款 Iron Software 產品的價格購買五款 Iron Software 產品套裝。獲取更多信息請從這裡 連結.

< 上一頁
QR Code 提取工具(示例工具)
下一個 >
從圖像讀取QR碼的在線工具

準備開始了嗎? 版本: 2024.10 剛剛發布

免費 NuGet 下載 總下載次數: 1,203,227 查看許可證 >