Giter Site home page Giter Site logo

czxing's Introduction

GitHub release

CZXing

C++ port of ZXing for Android

底层使用C++来处理图像及解析二维码,并且加入了OpenCV来解析图像,可以在更远的距离识别出二维码。

使用

在gradle中:

implementation 'me.devilsen:CZXing:0.5'

建议加入abiFilters

    defaultConfig {
        
        // 其他设置...

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

1. 直接使用

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

Resources resources = getResources();
List<Integer> scanColors = Arrays.asList(resources.getColor(R.color.scan_side), resources.getColor(R.color.scan_partial), resources.getColor(R.color.scan_middle));

Scanner.with(this)
        .setBorderColor(resources.getColor(R.color.box_line)) // 扫码框边框颜色
        .setCornerColor(resources.getColor(R.color.corner))   // 扫码框角颜色
        .setScanLineColors(scanColors)                        // 扫描线颜色(这是一个渐变颜色)
        .setDelegate(new ScanActivityDelegate.OnScanDelegate() {
            @Override
            public void onScanResult(String result) {
                Intent intent = new Intent(MainActivity.this, DelegateActivity.class);
                intent.putExtra("result", result);
                startActivity(intent);
            }
        })
        .start();

2. 自定义界面

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

<me.devilsen.czxing.view.ScanView
    android:id="@+id/surface_view_scan"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

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

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

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

3. 生成二维码

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

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

效果展示

点击观看

apk下载

设计思路

czxing's People

Contributors

devilsen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.