Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

CZXing

> 编程语言
Open source

Make you have the QRCode Scan ability like WeChat!

1.1K stars0 likes0 views
WebsiteGitHub

About

Make you have the QRCode Scan ability like WeChat!

CZXing

C++ port of ZXing for Android

拥有和微信一样的扫码能力!

使用

在gradle中:

groovy
// 迁移至 Maven Central
implementation 'io.github.devilsen:czxing:latestVersion'

建议加入abiFilters

gradle
defaultConfig {
    
    // 其他设置...

    ndk {
        // 设置支持的so库架构,设置一个可以减小包的大小
        abiFilters "armeabi-v7a","arm64-v8a"
    }
}

如果下载失败,可以在根目录加入阿里云的镜像

gradle
maven { url 'https://maven.aliyun.com/repository/central' }

关于 1.2.0

注:请先下载 模型 到本地使用

  • 1.2.0 加入了微信的解码和超分能力,识别能力理论上和微信是一致的。
  • 此版本经过了大量重构,可以更方便的使用各个组件,比如想拥有更自定义化的界面可以直接使用 DecodeEngine 作为内部的解码引擎,如果想直接使用Camera,可以使用 CameraView 来直接使用相机界面,此外还有封装好的识别界面 DetectView 和拥有识别流程的 ScanLayout 界面。
  • 如果觉得 sdk 版本过高,可以直接使用 1.1.0 后期将重新编译 OpenCV 降低 sdk 的需求版本。

1. 直接使用

你可以直接使用已经封装好的ScanActivity作为扫码界面

…

混淆配置

-keep class me.devilsen.czxing.**
-keep class me.devilsen.czxing.** { *; }

2. 自定义界面

或者使用ScanView来自定义你的界面

xml

在自定义的Activity中你需要接管ScanView的生命周期,具体可以参看ScanActivity界面,同时设定setScanListener()

java
mScanView.setScanListener(new ScanListener() {
    @Override
    public void onScanSuccess(String result, BarcodeFormat format) {
        // 扫码成功
    }

    @Override
    public void onOpenCameraError() {
        // 打开相机出错
    }
});

更多API请参考CustomizeActivity

3. 生成二维码

调用以下代码,可生成二维码的bitmap,Color为可选参数,默认为黑色。

简易调用

java
BarcodeWriter writer = new BarcodeWriter();
Bitmap bitmap = writer.write("Hello World", BarCodeUtil.dp2px(this, 200), BarCodeUtil.dp2px(this, 200), Color.RED);

完整调用

java
/**
* 生成图片
*
* @param text   要生成的文本
* @param width  图片宽
* @param height 图片高
* @param color  要生成的二维码颜色
* @param format 要生成的条码格式
* @param logo   放在中间的logo
* @return 条码bitmap
*/
private Bitmap write(String text, int width, int height, int color, BarcodeFormat format, Bitmap logo)

4. 识别图片中的二维码

java
// 适当压缩图片
Bitmap bitmap = BitmapUtil.getDecodeAbleBitmap(picturePath);
// 这个方法因为要做bitmap的变换,所以比较耗时,推荐放到子线程执行
CodeResult result = BarcodeReader.getInstance().read(bitmap);
if (result == null) {
  Log.d("Scan >>> ", "no code");
  return;
} else {
  Log.d("Scan >>> ", result.getText());
}

5. 测试Case

效果展示

远距离扫码演示

apk下载

设计思路

License

Copyright 2019 Devilsen

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C++androidbarcodejavaqrcode

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言