条码工具

QR码库(开发者指南)

发布 2022年五月10日
分享:

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 画布和 JavaScript API 的所有复杂性,同时还提供了合理的默认值。

QuaggaJS 已被开发人员和设计师广泛使用,他们希望创建数字营销解决方案,将二维码融入设计中。该库还兼容 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 的海龟模块相似,因此您可以很快熟练掌握。Segno 在设计时考虑到了简便性,因此开发人员无需事先了解条形码生成知识即可使用。不过,它也有一个强大的应用程序接口(API),如果开发人员想从条形码中获得更多信息,可以很容易地扩展 Segno 的功能。

Segno 的独特功能包括:根据条形码的数据字段,以多种方式生成相同的条形码图像;支持固定尺寸、可变尺寸或两者兼有;支持高分辨率光栅输出;以及带有工具提示的侧边栏,可帮助用户生成图像。以下是在 Python 项目中使用 Segno 库的代码示例:

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 因其易用性和高性能而成为当今发展最快的程序库之一。IronBarcode 可在 iOS、Android 和 Web 浏览器上运行,无需进行任何更改或修改,是您下一个项目的绝佳选择。该库为条形码生成提供了一个抽象层,同时还提供了一套标准实用程序和代码片段以方便开发。导入该库并将生成的代码传递给创建条形码方法是非常有用的。让我们通过代码示例来了解该库的操作步骤。

代码示例

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 库创建和读取二维码。使用起来非常简单。您只需导入该库并编写几行代码,您的条形码就可以使用和读取了。

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 有三种定价方案。您可以选择最适合您需要的方案。您还可以以 2 个 Iron 软件产品的价格购买 5 个 Iron 软件产品的套装。获取更多信息 链接.

< 前一页
QR码提取器(示例工具)
下一步 >
在线工具中的二维码读取器

准备开始了吗? 版本: 2024.8 刚刚发布

免费NuGet下载 总下载量: 1,167,541 查看许可证 >