Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xvrh/zxing-dart
This package is a pure Dart port of the ZXing ("zebra crossing") Java library.
https://github.com/xvrh/zxing-dart
barcode dart dartlang zxing
Last synced: 3 months ago
JSON representation
This package is a pure Dart port of the ZXing ("zebra crossing") Java library.
- Host: GitHub
- URL: https://github.com/xvrh/zxing-dart
- Owner: xvrh
- License: bsd-3-clause
- Created: 2021-02-16T11:36:41.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-04-03T07:58:32.000Z (10 months ago)
- Last Synced: 2024-06-19T05:54:45.914Z (7 months ago)
- Topics: barcode, dart, dartlang, zxing
- Language: Dart
- Homepage:
- Size: 123 MB
- Stars: 26
- Watchers: 3
- Forks: 7
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
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](https://img.shields.io/pub/v/zxing2.svg)](https://pub.dartlang.org/packages/zxing2)
[![Build Status](https://github.com/xvrh/zxing-dart/workflows/Build/badge.svg?branch=master)](https://github.com/xvrh/zxing-dart)
[![codecov](https://codecov.io/gh/xvrh/zxing-dart/graph/badge.svg?token=UGGAJMNLBC)](https://codecov.io/gh/xvrh/zxing-dart)## Getting started
### QR Code
#### Decoding
The `QRCodeReader` class takes a list of bytes and returns the decoded barcode.
```dart
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.
```dart
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.