zxing2
Dart로 구현된 다중 형식의 1차원/2차원 바코드 이미지 처리 라이브러리입니다. 이는 안드로이드 라이브러리의 포트입니다.
이 패키지는 ZXing("지브라 크로싱") 자바 라이브러리의 순수한 다트 포트입니다.
^1.2.0^1.15.0^1.0.0^1.3.0————{"git":{"url":"https://github.com/xvrh/project_tools.dart.git"}}———아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
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
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);
}
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);
}
The example folder contains a full example that uses the official camera plugin connected to this
package to decode barcode from the bytes stream.