Giter Site home page Giter Site logo

wxb-simple / android-zbar-sdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yanzhenjie/android-zbar-sdk

0.0 0.0 0.0 8.51 MB

:link: android-zbar-sdk, provide jni source, so file and jar file used alone, gradle/maven remote dependencies.

Home Page: https://github.com/yanzhenjie/android-zbar-sdk

License: GNU Lesser General Public License v2.1

Shell 19.78% C++ 4.34% C 64.99% Java 0.44% Assembly 0.03% Makefile 3.74% HTML 0.31% Batchfile 0.34% M4 4.12% Roff 1.90%

android-zbar-sdk's Introduction

Zbar and libiconv are based on LGPL-2.1 open source, based on LGPL-2.1, I organized the Android platform for the ZBar, to facilitate the use of developers.

中文文档

Most Android developers are relatively unfamiliar to jni, especially in the compilation of Zbar need to compile libiconv, so I have sorted out the full jni code.

I have the Zbar available, the following you can choose to use:

  1. can be directly ndk-build compiled JNI source
  2. Jar packages and so files that can be used alone
  3. can be remotely dependent on the native Zbar
  4. Encapsulated Zbar can directly scan the camera

I used the libiconv is released at 2017-02-02 the latest version 1.15.

zbar: https://github.com/ZBar/ZBar
libiconv: https://www.gnu.org/software/libiconv

Usage

Only core function of ZBar

If you only want to identify the barcode/QRCode data in byte[], then you only need to rely on native ZBar.

Add dependencies:

  • jar file and so file jar file in the android-zbar-sdk/jar folder, so files in the android-zbar-sdk\zbar\src\main\jniLibs folder.

  • Gradle

compile 'com.yanzhenjie.zbar:zbar:1.0.0'
  • Maven
<dependency>
  <groupId>com.yanzhenjie.zbar</groupId>
  <artifactId>zbar</artifactId>
  <version>1.0.0</version>
  <type>pom</type>
</dependency>

Note: The use of remote dependencies will load all the files so the platform, if you just want to rely on some of these platforms, then you need to add the compilation configuration:

defaultConfig {
    applicationId ...
    ...

    ndk {
        abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips', 'mips64', 'x86', 'x86_64'
    }
}

For example, you only need armeabi and armeabi-v7a:

ndk {
    abiFilters 'armeabi', 'armeabi-v7a'
}

Zbar's core recognition barcode/QRCode code is as follows.

byte[] imageData = ...;

Image barcode = new Image(size.width, size.height, "Y800");
barcode.setData(imageData);
// Set the image capture area.
// barcode.setCrop(startX, startY, width, height);

String qrCodeString = null;

int result = mImageScanner.scanImage(barcode);
if (result != 0) {
    SymbolSet symSet = mImageScanner.getResults();
    for (Symbol sym : symSet)
        qrCodeString = sym.getData();
}

if (!TextUtils.isEmpty(resultStr)) {
    // Successfully.
}

Not only that, you can also use the camera to combine this code to identify barcode/QRCode.

There are examples of camera scans in Demo.

Package of Camera and ZBar

If you are not familiar with the camera, you can also use my camera and ZBar package, will be very simple to use the camera to complete the two-dimensional code scan.

Add dependencies:

  • Gradle
compile 'com.yanzhenjie.zbar:camera:1.0.0'
  • Maven
<dependency>
  <groupId>com.yanzhenjie.zbar</groupId>
  <artifactId>camera</artifactId>
  <version>1.0.0</version>
  <type>pom</type>
</dependency>

This is a simple example in Activity:

activity_scan.xml

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.yanzhenjie.zbar.camera.CameraPreview
        android:id="@+id/capture_preview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
<RelativeLayout/>

ScanActivity.java

private CameraPreview mPreview;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scan);
    
    mPreview = (CameraPreview) findViewById(R.id.capture_preview);
    mPreview.setScanCallback(callback);
}

/**
 * Start camera.
 */
private void startScan() {
    mPreview.start();
}

/**
 * Stop camera.
 */
private void stopScan() {
    mPreview.stop();
}

/**
 * Result.
 */
private ScanCallback callback = new ScanCallback() {
    @Override
    public void onScanResult(String content) {
        // Successfully.
    }
};

@Override
protected void onPause() {
    // Must be called here, otherwise the camera should not be released properly.
    stopScan();
    super.onPause();
}

The actual development you need to pay attention to the RunTime Permission, the camera is occupied and so on.

For RunTime-Permission, I recommend you use AndPermission:
https://github.com/yanzhenjie/AndPermission

Such as whether the camera started successfully:

/**
 * Start camera.
 */
private void startScan() {
    if(mPreview.start()) {
        // The camera starts successfully and you can start a scan animation.
    } else {
        // The camera starts failing and you can tell the user.
    }
}

For more examples please refer to sample.

Proguard-rules

If you already have this rule, then you do not have to add.

-keepclassmembers class * {
    native <methods>;
}

-keepclasseswithmembernames class * {
    native <methods>;
}

android-zbar-sdk's People

Contributors

spadix0 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.