Web Demos

BARCODE READER SDK DEMO

Explore the flexibe barcode reading settings to optimize for your specific usage scenario.

WEB TWAIN SDK DEMO

Try the most popular web scanner features: scan images, import local images and PDF files, edit, save to local, upload to database, and etc.

BARCODE READER JAVASCRIPT DEMO

Transform any camera-equipped devices into real-time, browser-based barcode and QR code scanners.

MRZ SCANNER WEB DEMO

Detects the machine-readable zone of a passport, scans the text, and parses into human-readable data.

APP STORE DEMOS

BARCODE READER SDK FOR IOS

BARCODE READER SDK FOR ANDROID

VIEW MORE DEMOS >
Dev Center
Table of contents

Thanks for downloading Dynamsoft Barcode Reader Package!

Your download will start shortly. If your download does not begin, click here to retry.

Video Decoding Methods

Note:

  • You have to include CameraEnhancer when using Video Decoding Methods.
  • CameraEnhancer provide APIs that help you quickly deploy a camera module and capture video streaming for barcode decoding.
  • Through Video Decoding Methods you can control whether to start video streaming barcode decoding and get the barcode results.
  • Be sure that your BarcodeReader version is 8.9.0+ and CameraEnhancer is 2.1.0+ when using the methods on this page.
Method Description
setCameraEnhancer Bind a Camera Enhancer instance to the Barcode Reader.
startScanning Start the barcode reading thread.
stopScanning Stop the barcode reading thread.
setTextResultListener Set callback interface to process text results generated during frame decoding.
setIntermediateResultListener Set callback interface to process intermediate results generated during frame decoding.
setMinImageReadingInterval Set the minimum interval between two barcode decoding.
getMinImageReadingInterval Get the minimum interval between two barcode decoding.
setImageSource Set the ImageSource as the source of video streaming.

setCameraEnhancer

Bind a Dynamsoft Camera Enhancer instance to the Barcode Reader. Dynamsoft Camera Enhancer is designed for video streaming processing scenarios. It can help the Barcode Reader to acquire video frames continuously for video streaming barcode decoding.

void setCameraEnhancer(CameraEnhancer mCameraEnhancer)

Parameters

mCameraEnhancer: An instance of Dynamsoft Camera Enhancer.

Code Snippet

This code snippet displays a complete code on how to add CameraEnhancer to your project and start to use Video Decoding Methods to decode and get barcode results from the video streaming.

BarcodeReader reader;
CameraEnhancer mCameraEnhancer;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Be sure that you have added a cameraView in the layout file.
    DCECameraView cameraView = findViewById(R.id.cameraView);
    try {
        // Create an instance of Dynamsoft Barcode Reader.
        reader = new BarcodeReader();
    } catch (BarcodeReaderException e) {
        e.printStackTrace();
    }
    mCameraEnhancer = new CameraEnhancer(MainActivity.this);
    mCameraEnhancer.setCameraView(cameraView);

    // Bind the Camera Enhancer instance to the Barcode Reader instance.
    reader.setCameraEnhancer(mCameraEnhancer);

    // Result callback configurations
    TextResultListener mTextResultListener = new TextResultListener() {
        // Obtain the recognized barcode results and display.
        @Override
        public void textResultCallback(int id, ImageData imageData, TextResult[] textResults) {
            // Add your code to execute when barcode results are returned.
        }
    };
    reader.setTextResultListener(mTextResultListener);
}
@Override
public void onResume() {
    // Open the camera and start video barcode reading
    try {
        mCameraEnhancer.open();
    } catch (CameraEnhancerException e) {
        e.printStackTrace();
    }
    reader.startScanning();
    super.onResume();
}

@Override
public void onPause() {
    // Stop video barcode reading
    try {
        mCameraEnhancer.close();
    } catch (CameraEnhancerException e) {
        e.printStackTrace();
    }
    reader.stopScanning();
    super.onPause();
}

startScanning

Start the video streaming barcode decoding thread. Please be sure that you have bound a CameraEnhancer or ImageSource to the barcode reader before you trigger startScanning.

void startScanning()

Code Snippet

You can view the complete code snippet in setCameraEnhancer.

stopScanning

Stop the video streaming barcode decoding thread.

void stopScanning()

Code Snippet

You can view the complete code snippet in setCameraEnhancer.

setTextResultListener

Set a callback interface to process text results generated during frame decoding.

void setTextResultListener(TextResultListener textResultListener)

Parameters

textResultCallback: Callback interface.

Code Snippet

You can view the complete code snippet in setCameraEnhancer.

setIntermediateResultListener

Set a callback interface to process intermediate results generated during frame decoding.

void setIntermediateResultListener(IntermediateResultListener intermediateResultListener)

Parameters

intermediateResultCallback: Callback interface.

Code Snippet

The usage of intermediateResultListener is similar to the textResultListener. You can view detailed code snippet in setCameraEnhancer and replace the textResultListener code with the intermediateResultListener code.

BarcodeReader reader = new BarcodeReader();
PublicRuntimeSettings settings = reader.getRuntimeSettings();
// You can set intermediateResult type when using intermediateResultListener
settings.intermediateResultTypes = EnumIntermediateResultType.IRT_ORIGINAL_IMAGE | EnumIntermediateResultType.IRT_COLOUR_CLUSTERED_IMAGE | EnumIntermediateResultType.IRT_COLOUR_CONVERTED_GRAYSCALE_IMAGE;
reader.updateRuntimeSettings(settings);
reader.setIntermediateResultListener(new IntermediateResultListener() {
    @Override
    public void intermediateResultCallback(int i, ImageData imageData, IntermediateResult[] intermediateResults) {
        //TODO add your code for using intermediate results           
    }
});

setMinImageReadingInterval

Set the minimum interval between two barcode decoding. The unit of measure for this property is milliseconds. If the previous barcode decoding is finished in n milliseconds (n < minImageReadingInterval), the barcode decoding thread will be paused by minImageReadingInterval - n milliseconds.

void setMinImageReadingInterval(int interval);

Parameters

interval: The minimum interval between two barcode decoding. The value is measured by millisecond.

Code Snippet

reader.setMinImageReadingInterval(500);

getMinImageReadingInterval

Get the minimum interval between two barcode decoding.

int getMinImageReadingInterval();

Return Value

The current minimum interval setting.

Code Snippet

int interval = reader.getMinImageReadingInterval();

setImageSource

Set the ImageSource as the source of video streaming.

void setImageSource(ImageSource source);

Parameters

source: The source of images

Code Snippet

Here we use CameraX as the example of the image source. The following code displays how to use CameraX to capture video frames and tranfer the video frames into ImageData.

private ImageData mImageData;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    try {
        mReader = new BarcodeReader();
    } catch (BarcodeReaderException e) {
        e.printStackTrace();
    }
    // Set image source
    mReader.setImageSource(new ImageSource() {
        @Override
        // Configure the getImage method.
        public ImageData getImage() {
            return mImageData;
        }
    });
    // Configure the listener to receive the TextResult from the textResultCallback
    mReader.setTextResultListener(new TextResultListener() {
        @Override
        public void textResultCallback(int i, ImageData imageData, TextResult[] textResults) {
            // Add your code to execute when iTextResult is received.
        }
    }
}
// onResume start barcode decoding.
@Override
protected void onResume() {
    super.onResume();
    mReader.startScanning();
}
// onPause stop barcode decoding.
@Override
protected void onPause() {
    super.onPause();
    mReader.stopScanning();
}
// Get the buffer image from CameraX Analyzer and generate the image into iImageData.
private ImageAnalysis.Analyzer mBarcodeAnalyzer = new ImageAnalysis.Analyzer() {
    @Override
    public void analyze(@NonNull ImageProxy imageProxy) {
        try {
            if(isShowingDialog) {
                mImageData = null;
                return;
            }
            byte[] data = new byte[imageProxy.getPlanes()[0].getBuffer().remaining()];
            imageProxy.getPlanes()[0].getBuffer().get(data);
            int nRowStride = imageProxy.getPlanes()[0].getRowStride();
            int nPixelStride = imageProxy.getPlanes()[0].getPixelStride();
            ImageData imageData = new ImageData();
            imageData.bytes = data;
            imageData.width = imageProxy.getWidth();
            imageData.height = imageProxy.getHeight();
            imageData.stride = nRowStride;
            imageData.format =EnumImagePixelFormat.IPF_NV21;
            imageData.orientation = imageProxy.getImageInfo().getRotationDegrees();
            mImageData = imageData;
        } finally {
            imageProxy.close();
        }
    }
};

This page is compatible for:

Version 7.5.0

Is this page helpful?

YesYes NoNo

In this article:

latest version

  • Latest version
  • Version 9.x
    • Version 9.2.11
    • Version 9.2.10
    • Version 9.0.1
    • Version 9.0.0
  • Version 8.x
    • Version 8.9.3
    • Version 8.9.0
    • Version 8.8.7
    • Version 8.8.5
    • Version 8.8.3
    • Version 8.8.0
    • Version 8.6.3
    • Version 8.6.0
    • Version 8.4.0
    • Version 8.2.5
    • Version 8.2.3
    • Version 8.2.1
    • Version 8.2.0
    • Version 8.1.3
    • Version 8.1.2
    • Version 8.1.0
    • Version 8.0.0
  • Version 7.x
    • Version 7.6.0
    • Version 7.5.0
Change +
© 2003–2022 Dynamsoft. All rights reserved.
Privacy Statement / Site Map / Home / Purchase / Support