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

GitHub 代码仓xvrh/zxing-dart

zxing-dart

此包是 ZXing(“斑马条码”)Java 库的纯 Dart 版本。

zxing-dart 项目封面
星标
31
复刻
14
最近推送(UTC)
2025年6月6日
项目状态
未归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

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.

Xavier H. GitHub avatar
GitHub 作者

Xavier H. ↗

Web & mobile developer

FreelanceBelgium
语言Dart

分类

此仓库发布的插件

使用的依赖

依赖清单 12 项

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗