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.

Decode Methods

Method Description
decodeBuffer Decode barcodes from raw buffer.
decodeFile Decode barcodes from a specified image file.
decodeFileInMemory Decode barcodes from an image file in memory.
decodeBase64String Decode barcodes from a base64 encoded string.
decodeBufferedImage Decodes barcode from a buffered imag (bitmap).
initIntermediateResult Inits an intermediateResult struct with default values.
decodeIntermediateResults Decodes barcode from intermediate results.

decodeBuffer

Decode barcodes from the memory buffer containing image pixels in defined format.

TextResult[] decodeBuffer(byte[] buffer, int width, int height, int stride, int enumImagePixelFormat) throws BarcodeReaderException

Parameters

buffer: The array of bytes that contain the image data.
Width: The width of the image in pixels.
Height: The height of the image in pixels.
Stride: The stride is measured by the byte length of each line in the buffer.
format: The image pixel format used in the image byte array.

Return Value

The TextResult of all successfully decoded barcodes. TextResult includes the text, format and other information about the barcodes.

Exceptions

BarcodeReaderException

There are several approaches for you to get a buffered image.

Get ImageData from DCEFrame

You can import CameraEnhancer to acquire buffered video frames from frameOutputCallback or videoBuffer of DCE.

Code Snippet

/*You can get frames from frame output call back if you import dynamsoft camera enhancer package.*/
/*You can get all the required parameters of decodeBuffer from DCEFrame.*/
import com.dynamsoft.dce.CameraEnhancer;

BarcodeReader reader = new BarcodeReader();
mCameraEnhancer.addListener(new DCEFrameListener() {
  @Override
  public void frameOutputCallback(DCEFrame dceFrame, long l) {
    try {
      TextResult[] results = reader.decodeBuffer(dceFrame.getImageData(),dceFrame.getWidth(),dceFrame.getHeight(),dceFrame.getStrides()[0],dceFrame.getPixelFormat());
    } catch (BarcodeReaderException e) {
      e.printStackTrace();
    }
  }
});

Get ImageData from Android Camera2

When you are using Android Camera2, you can get video frames from ImageReader.

Code Snippet

previewReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {
  @Override
  public void onImageAvailable(ImageReader reader) {
    Image mImage = reader.acquireLatestImage();
    ByteBuffer bufferY = mImage.getPlanes()[0].getBuffer();
    int strideY = mImage.getPlanes()[0].getRowStride() / mImage.getPlanes()[0].getPixelStride();
    ByteBuffer bufferU = mImage.getPlanes()[1].getBuffer();
    int strideU = mImage.getPlanes()[1].getRowStride() / mImage.getPlanes()[1].getPixelStride();
    ByteBuffer bufferV = mImage.getPlanes()[2].getBuffer();
    int strideV = mImage.getPlanes()[2].getRowStride() / mImage.getPlanes()[2].getPixelStride();
    int padingY = mImage.getPlanes()[0].getRowStride() - mImage.getWidth();
    int padingU = mImage.getPlanes()[1].getRowStride() - mImage.getWidth();
    byte[] newData = new byte[bufferY.limit()];
    newData = new byte[bufferY.limit() + bufferU.limit() + 1 + padingY + padingU];
    bufferV.get(newData, bufferY.limit() + padingY, 1);
    bufferU.get(newData, bufferY.limit() + padingY + 1, bufferU.limit());
    bufferY.get(newData, 0, bufferY.limit());
    int[] strides = new int[]{strideY, strideU, strideV};
    try {
      TextResult[] results = reader.decodeBuffer(newData, strideY, mImage.getHeight(), strideY, 3);
    } catch (BarcodeReaderException e) {
      e.printStackTrace();
    }
  }
},handler);

decodeFile

Decode barcodes from a specified image file.

TextResult[] decodeFile(String fileFullPath) throws BarcodeReaderException

Parameters

fileFullPath: A string defining the file path. It supports BMP, TIFF, JPG, PNG and PDF files.

Return Value

The TextResult of all successfully decoded barcodes. TextResult includes the text, format and other information about the barcodes.

Exceptions

BarcodeReaderException

Code Snippet

BarcodeReader reader = new BarcodeReader();
/*Init DBR license before decoding*/
/*Read external storage permission is required when decoding from a file*/
TextResult[] result = reader.decodeFile(Environment.getExternalStorageDirectory().toString()+"your file path");

decodeFileInMemory

Decode barcodes from an image file in memory.

fileBytes

TextResult[] decodeFileInMemory(byte[] fileBytes) throws BarcodeReaderException

Parameters

fileBytes: The image file bytes in memory.

Return Value

The TextResult of all successfully decoded barcodes. TextResult includes the text, format and other information about the barcodes.

Exceptions

BarcodeReaderException

Code Snippet

BarcodeReader reader = new BarcodeReader();
/*Init DBR license before decoding
get bufferBytes from other component*/
TextResult[] result = reader.decodeFileInMemory(bufferBytes);

fileStream

TextResult [] decodeFileInMemory(InputStream fileStream) throws BarcodeReaderException, IOException

Parameters

fileStream: The image file bytes in memory.

Return Value

The TextResult of all successfully decoded barcodes. TextResult includes the text, format and other information about the barcodes.

Exceptions

BarcodeReaderException, IOException

Code Snippet

BarcodeReader reader = new BarcodeReader();
/*Init DBR license before decoding
get bufferBytes from other component*/
TextResult[] result = reader.decodeFileInMemory(fileStream);

decodeBase64String

Decode barcode from an image file encoded as a base64 string.

TextResult[] decodeBase64String(String base64) throws BarcodeReaderException

Parameters

base64: A base64 encoded string that represents an image.

Return Value

The TextResult of all successfully decoded barcodes. TextResult includes the text, format and other information about the barcodes.

Exceptions

BarcodeReaderException

Code Snippet

BarcodeReader reader = new BarcodeReader();
/*Init DBR license before decoding*/
TextResult[] result = reader.decodeBase64String("file in base64 string");

decodeBufferedImage

Decodes barcode from a buffered image (bitmap).

TextResult[] decodeBufferedImage(Bitmap image) throws BarcodeReaderException

Parameters

image: The image to be decoded.

Return Value

The TextResult of all successfully decoded barcodes. TextResult includes the text, format and other information about the barcodes.

Exceptions

BarcodeReaderException, IOException

Code Snippet

BarcodeReader reader = new BarcodeReader();
/*Init DBR license before decoding*/
/*get BufferedImage input from other component*/
TextResult[] result = reader.decodeBufferedImage(input);

initIntermediateResult

Inits an intermediateResult struct with default values.

IntermediateResult initIntermediateResults(int resultType) throws BarcodeReaderException

Parameters

resultType: An int value that indicates the intermediate result type. The int value should be available in (EnumIntermediateResultType).

Return Value

An IntermediateResult struct with default values.

Exceptions

BarcodeReaderException

Code Snippet

BarcodeReader reader = new BarcodeReader();
/*Init DBR license before decoding*/
IntermediateResult imResult = reader.initIntermediateResult(EnumIntermediateResultType.IRT_ORIGINAL_IMAGE);

decodeIntermediateResults

Decodes barcode from intermediate results.

TextResult[] decodeIntermediateResults(IntermediateResult[] results) throws BarcodeReaderException

Parameters

results: An array of intermediate result.

Return Value

The TextResult of all successfully decoded barcodes. TextResult includes the text, format and other information about the barcodes.

Exceptions

BarcodeReaderException

Code Snippet

BarcodeReader reader = new BarcodeReader();
/*Init DBR license before decoding*/
PublicRuntimeSettings settings = reader.getRuntimeSettings();
settings.intermediateResultTypes = EnumIntermediateResultType.IRT_ORIGINAL_IMAGE;
reader.updateRuntimeSettings(settings);
reader.decodeFile("your file path");
IntermediateResult[] irtResult = reader.getIntermediateResults();
TextResult[] result = reader.decodeIntermediateResults(irtResult);

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