搜索插件、代码仓与 APP 分类

插件详情v0.2.4

zxing2

一个用 Dart 实现的多格式一维/二维条形码图像处理库。这是 Android 库的移植版本。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
33.2万
喜欢数
76
Pub 分数
160

安装插件

flutter pub add zxing2

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

zxing2 是 ZXing 条形码处理库的 Dart 实现,支持多格式的一维和二维条形码扫描与生成。它是流行的 Android ZXing 库的移植版本,使 Flutter 应用能够实现跨平台的条形码功能。该包可在 Android、iOS、Web、macOS、Windows 和 Linux 上运行,非常适合需要在各种设备上可靠读取和写入条形码的应用程序。

适合场景

  • 在移动应用中扫描二维码
  • 生成条形码以进行库存跟踪
  • 在零售应用中读取产品代码
  • 在Web应用程序中集成条形码输入
  • 支持带条形码的文档扫描

主要特点

  • 跨平台条形码支持
  • 条形码检测的高精度
  • 支持多种格式(二维码、数据矩阵、PDF417 等)
  • 轻量且快速处理
  • 与 Flutter UI 的轻松集成

适合对象

  • 需要条形码扫描的移动和网络应用
  • 电子商务和物流应用
  • 库存和资产管理工具
  • 需要通过条形码进行安全数据编码的应用程序
  • 寻求在多个平台上实现原生性能的开发者

使用建议

  • 在移动平台上需要相机权限
  • 可能需要针对低端设备进行优化
  • 仅限基于图像的条形码处理
  • 没有用于扫描的内置UI组件
  • 性能取决于图像质量和光照条件

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

zxing-dart

ZXing ("zebra crossing") is an open-source, multi-format 1D/2D barcode image processing library.
This package is a pure Dart port of the original Java library.

For now, it only supports QR-Code (encoding and decoding). New format can easily be added if this port proves useful.

pub package Build Status codecov

Buy Me A Coffee

Getting started

QR Code
Decoding

The QRCodeReader class takes a list of bytes and returns the decoded barcode.

import 'dart:io';
import 'package:image/image.dart' as img;
import 'package:zxing2/qrcode.dart';

void main() {
  var image = img.decodePng(File('tool/example.png').readAsBytesSync())!;

  LuminanceSource source = RGBLuminanceSource(
      image.width,
      image.height,
      image
          .convert(numChannels: 4)
          .getBytes(order: img.ChannelOrder.abgr)
          .buffer
          .asInt32List());
  var bitmap = BinaryBitmap(GlobalHistogramBinarizer(source));

  var reader = QRCodeReader();
  var result = reader.decode(bitmap);
  print(result.text);
}
Encoding

The QRCodeReader class takes a list of bytes and returns the decoded barcode.

import 'dart:io';
import 'package:image/image.dart' as img;
import 'package:zxing2/qrcode.dart';

void main() {
  var qrcode = Encoder.encode('ABCDEF', ErrorCorrectionLevel.h);
  var matrix = qrcode.matrix!;
  var scale = 4;

  var image = img.Image(
      width: matrix.width * scale,
      height: matrix.height * scale,
      numChannels: 4);
  for (var x = 0; x < matrix.width; x++) {
    for (var y = 0; y < matrix.height; y++) {
      if (matrix.get(x, y) == 1) {
        img.fillRect(image,
            x1: x * scale,
            y1: y * scale,
            x2: x * scale + scale,
            y2: y * scale + scale,
            color: img.ColorRgba8(0, 0, 0, 0xFF));
      }
    }
  }
  var pngBytes = img.encodePng(image);
  File('tool/examples/encoded.png').writeAsBytes(pngBytes);
}

Flutter

The example folder contains a full example that uses the official camera plugin connected to this package to decode barcode from the bytes stream.

所属分类

依赖

依赖清单 4 项

源码仓库

使用此插件的项目