10 Star 4 Fork 14

OpenHarmony-TPC / zxing

加入 Gitee
与超过 800 万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README.md

zxing

简介

zxing是一个解析/生成一维码/二维码的库。

code128.png

qrCode.png

支持的码格式

1D product 1D industrial 2D
UPC-A Code 39 QR Code
UPC-E Code 93 Data Matrix
EAN-8 Code 128 Aztec
EAN-13 Codabar PDF 417
RSS-14 ITF MaxiCode
RSS-Expanded

下载安装

npm install @ohos/zxing --save

OpenHarmony npm环境配置等更多内容,请参照 如何安装OpenHarmony npm包

使用说明

解码

import {MultiFormatReader, BarcodeFormat, DecodeHintType, RGBLuminanceSource, BinaryBitmap, HybridBinarizer } from "@ohos/zxing";
const hints = new Map();
const formats = [BarcodeFormat.QR_CODE];
hints.set(DecodeHintType.POSSIBLE_FORMATS, formats);
const reader = new MultiFormatReader();
reader.setHints(hints);
const luminanceSource = new RGBLuminanceSource(luminances, width, height);
const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
let result = reader.decode(binaryBitmap);
let text = result.getText();

编码

import {BarcodeFormat, MultiFormatWriter, BitMatrix, ZXingStringEncoding, EncodeHintType} from '@ohos/zxing';
 const encodeHintTypeMap = new Map();
 //设置二维码边空白的宽度
 encodeHintTypeMap.set(EncodeHintType.MARGIN, 0);
 const writer: MultiFormatWriter = new MultiFormatWriter();
 let matrix: BitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, width, height, encodeHintTypeMap);

OpenHarmony上我们是用image组件显示图片的,所以需要将matrix转化成pixelMap这样才可以显示在image组件上面。

1.需要将matrix转成pixelMap的buffer。

2.在根据这个buffer去创建pixelMap。

3.输入的解析生成码的一些限制:

codabar只能是数字

ena8 只能是7位数字

ena13只能是12位数字

ITF码只能是数字,且需要双数,长度要>=6才能解析生成码

upcA只能数字,且长度只能是11位。

upcE只能数字,且长度只能是7位

具体操作细节可以看demo代码,主要转换逻辑都封装在imageUtils工具类中。

接口列表

编码

类名 方法名 功能
QRCodeWriter encode(contents: string,format: BarcodeFormat,width: int,height:int,hints: Map<EncodeHintType, any>): BitMatrix 生成QRCode码。
DataMatrixWriter encode(contents: string,format: BarcodeFormat,width: int,height:int,hints: Map<EncodeHintType, any>): BitMatrix 生成DataMatrix码。
AztecWriter encode(contents: string,format: BarcodeFormat,width: int,height:int,hints: Map<EncodeHintType, any>): BitMatrix 生成Aztec码。
PDF417Writer encode(contents: string,format: BarcodeFormat,width: int,height:int,hints: Map<EncodeHintType, any>): BitMatrix 生成PDF417码。
Code39Writer encode(contents: string,format: BarcodeFormat,width: int,height:int,hints: Map<EncodeHintType, any>): BitMatrix 生成Code39码。
Code93Writer encode(contents: string,format: BarcodeFormat,width: int,height:int,hints: Map<EncodeHintType, any>): BitMatrix 生成Code93码。
Code128Writer encode(contents: string,format: BarcodeFormat,width: int,height:int,hints: Map<EncodeHintType, any>): BitMatrix 生成Code128码。
CodaBarWriter encode(contents: string,format: BarcodeFormat,width: int,height:int,hints: Map<EncodeHintType, any>): BitMatrix 生成CodaBar码。
ITFWriter encode(contents: string,format: BarcodeFormat,width: int,height:int,hints: Map<EncodeHintType, any>): BitMatrix 生成ITF码。
UPCAWriter encode(contents: string,format: BarcodeFormat,width: int,height:int,hints: Map<EncodeHintType, any>): BitMatrix 生成UPCA码。
UPCEWriter encode(contents: string,format: BarcodeFormat,width: int,height:int,hints: Map<EncodeHintType, any>): BitMatrix 生成UPCE码。
EAN8Writer encode(contents: string,format: BarcodeFormat,width: int,height:int,hints: Map<EncodeHintType, any>): BitMatrix 生成EAN8码。
EAN13Writer encode(contents: string,format: BarcodeFormat,width: int,height:int,hints: Map<EncodeHintType, any>): BitMatrix 生成EAN13码。
MultiFormatWriter encode(contents: string,format: BarcodeFormat,width: int,height:int,hints: Map<EncodeHintType, any>): BitMatrix 这是一个工厂类方法,它为请求的条形码/二维码格式找到适当的编写器子类,并使用提供的内容编码二维码/条形码。

解码

类名 方法名 功能
QRCodeReader decode(image: BinaryBitmap, hints?: Map<DecodeHintType, any> | null): Result; 解析QRCode码。
DataMatrixReader decode(image: BinaryBitmap, hints?: Map<DecodeHintType, any> | null): Result; 解析DataMatrix码。
AztecReader decode(image: BinaryBitmap, hints?: Map<DecodeHintType, any> | null): Result; 解析Aztec码。
PDF417Reader decode(image: BinaryBitmap, hints?: Map<DecodeHintType, any> | null): Result; 解析PDF417码。
MaxiCodeReader decode(image: BinaryBitmap, hints?: Map<DecodeHintType, any> | null): Result; 解析MaxiCode码。
Code39Reader decode(image: BinaryBitmap, hints?: Map<DecodeHintType, any> | null): Result; 解析Code39码。
Code93Reader decode(image: BinaryBitmap, hints?: Map<DecodeHintType, any> | null): Result; 解析Code93码。
CodaBarReader decode(image: BinaryBitmap, hints?: Map<DecodeHintType, any> | null): Result; 解析CodaBar码。
Code128Reader decode(image: BinaryBitmap, hints?: Map<DecodeHintType, any> | null): Result; 解析Code128码。
ITFReader decode(image: BinaryBitmap, hints?: Map<DecodeHintType, any> | null): Result; 解析ITF码。
UPCAReader decode(image: BinaryBitmap, hints?: Map<DecodeHintType, any> | null): Result; 解析UPCA码。
UPCEReader decode(image: BinaryBitmap, hints?: Map<DecodeHintType, any> | null): Result; 解析UPCE码。
EAN8Reader decode(image: BinaryBitmap, hints?: Map<DecodeHintType, any> | null): Result; 解析EAN8码。
EAN13Reader decode(image: BinaryBitmap, hints?: Map<DecodeHintType, any> | null): Result; 解析EAN13码。
RSS14Reader decode(image: BinaryBitmap, hints?: Map<DecodeHintType, any> | null): Result; 解析RSS14码。
RSSExpandedReader decode(image: BinaryBitmap, hints?: Map<DecodeHintType, any> | null): Result; 解析RSSExpanded码。
MultiFormatReader decode(image: BinaryBitmap, hints?: Map<DecodeHintType, any> | null): Result; 这是一个工厂类方法,它为请求的条形码/二维码格式找到适当的解码器子类,并使用提供的内容解码二维码/条形码。

兼容性

支持 OpenHarmony API version 8 及以上版本。

项目目录

|---- Zxing  
|     |---- entry  # 示例代码文件夹
|     |---- zxing  # zxing库文件夹
|           |---- index.ets  # 对外接口
|     |---- README.MD  # 安装使用方法                    

贡献代码

使用过程中发现任何问题都可以提 Issue 给我们,当然,我们也非常欢迎你给我们发 PR

开源协议

本项目基于 MIT License ,请自由地享受和参与开源。

仓库评论 ( 0 )

你可以在登录后,发表评论

简介

暂无描述 展开 收起
TypeScript 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/openharmony-tpc/zxing.git
git@gitee.com:openharmony-tpc/zxing.git
openharmony-tpc
zxing
zxing
master

搜索帮助

120539 77c3c0f1 1850385 100910 489c739c 1850385