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.

ImageSource

Interface for producers of images. It can be implemented by developers to support other image sources, such as external cameras or image filesets.

How to Use:

  1. Use BarcodeReader.setImageSource to set ImageSource as the source of image.
  2. Add code in method getImage. When DBR finishes the current process and trying to start decoding from another image, it will call the getImage.
  3. Trigger BarcodeReader.startScanning to start the barcode decoding thread when all above are configured.
  4. When barcode decoding thread is started, users can stop the thread by calling BarcodeReader.stopScanning
interface com.dynamsoft.dbr.ImageSource
Method Description
getImage The method for users for complete. Get image/video from external sources and out put the data as ImageData.

getImage

The method for users for complete which returns ImageData. When using external sources, users can generate the external image source into ImageData and output them in method getImage so that the image can be recognized by the Barcode Reader.

The barcode reader will continuously use getImage to acquire ImageData for barcode decoding when:

ImageData getImage();

Return Value

An object of ImageData.

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 getImageData() {
            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 ImageData.
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