A new frame for decode QR code and bar code on Android

XCodeScanner

A new frame for decode QR code and bar code on Android. It's faster, simpler and more accurate. It's based on ZBar, compatible with Android4.0 (API14) and above.

Demo

Function

This project is based on the ZBar development. It has highly encapsulated the view, camera, and decoding, and reduces the coupling between the three and increases the flexibility of configuration.

View

AdjustTextureView, extended from TextureView, can correct the image according to its size, frame width and rotation angle, and solve abnormal problems such as preview image distortion.

ScannerFrameView, extended from View, you can customize the size, color, and animation of the scan box, the four corners, and the scan line by using xml properties or interfaces. The specific use of reference source code comments.

MaskRelativeLayout&MaskConstraintLayout，extended from RelativeLayout&ConstraintLayout, as the parentView of ScannerFrameView, used to draw the outer shadow of the scan box.

Camera

Compatible with android.hardware.camera2 and android.hardware.Camera API。

Open the camera from the child thread to prevent blocking of the main thread.

Use the singleton to prevent multiple instances from simultaneously operating the camera device to cause an exception.

According to the preview size, the image frame size, and the preview direction, the actual position of the scan frame on the image frame is calculated, can decode the scan box area only.

Use TextureReader instead of ImageReader, using openGL to draw the image texture, mainly to solve the problem of serious frame loss in the preview, real-time output YUV format image.

Decoding

Supports specified area decoding.

You can specify the type of barcode that needs to be decoded.

The callback result contains the barcode type and barcode precision. You can configure the dirty data filter rule.

UML

Gradle

Add the following code in module's build.gradle

dependencies {
implementation 'cn.simonlee.xcodescanner:zbar:1.1.5'
}

Usage

STEP.1

Get the CameraScanner instance in the Activity's onCreate, and set the monitor to CameraScanner and TextureView.

public void onRestart() {
//Some devices will call onSurfaceTextureAvailable to open the camera when they go to the foreground in the background.
if (mTextureView.isAvailable()) {
mCameraScanner.setSurfaceTexture(mTextureView.getSurfaceTexture());
mCameraScanner.setPreviewSize(mTextureView.getWidth(), mTextureView.getHeight());
mCameraScanner.openCamera(this.getApplicationContext());
}
super.onRestart();
}

Update plan

Support decode local pictures.

Solve the problems caused by changes in the TextureView size.

Support environmental brightness monitoring and support open the flash.

Supports Zxing.

Support generation QR code.

Changelog

V1.1.5 2018/05/01

Solve the problem of application permission crash.

Solve the problem of running a crash on the Meizu MX5.

Modify the implementation of ZBarDecoder and TextureReader to reduce CPU usage.

Add AdjustTextureView, extended from TextureView, for ease of compatibility testing.

The pause/delay decode interface is migrated from CameraScanner to GraphicDecoder. CameraScanner may continue to call back decodeSuccess after a pause because of asynchronous.

Release the open source library: cn.simonlee.xcodescanner:zbar:1.1.5.

V1.1.4 2018/04/26

Solve the crash problem when running on Android4.2.

Solve the problem that some low-end devices may preview severe dropped frames.

Solve the problem that OldCameraScanner does not start decoding by default.