1 Star 0 Fork 34

wangyingjun02 / zxing

forked from OpenHarmony-TPC / zxing 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

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

下载安装

ohpm install @ohos/zxing 

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

使用说明

解码

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; 这是一个工厂类方法,它为请求的条形码/二维码格式找到适当的解码器子类,并使用提供的内容解码二维码/条形码。

约束与限制

在下述版本验证通过:

DevEco Studio: 4.0 Canary2(4.0.3.317), SDK: API10 (4.0.9.5) DevEco Studio: 3.1 Beta2(3.1.0.400), SDK: API9 Release(3.2.11.9)

项目目录

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

贡献代码

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

开源协议

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

MIT License Copyright (c) 2022 Huawei Device Co., Ltd. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

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

搜索帮助