Addon.Barcode.Read()

Description

Read barcode on a specified image loaded in Dynamic Web TWAIN.

Syntax

Use it as an asynchronous method (recommended)

.Addon.Barcode.Read(sImageIndex, format, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);

Or use it as a synchronous method.

This will return the recognition result (type: <BarcodeResult>) directly.

.Addon.Barcode.Read(sImageIndex, format);

Parameters

<short> sImageIndex: specifies the index of the image.
<long> format: specifies the barcode format.


Numeric Value Value
183806 EnumDWT_BarcodeFormat.All
180702 EnumDWT_BarcodeFormat.OneD
2 EnumDWT_BarcodeFormat.CODABAR
4 EnumDWT_BarcodeFormat.CODE_39
8 EnumDWT_BarcodeFormat.CODE_93
16 EnumDWT_BarcodeFormat.CODE_128
32 EnumDWT_BarcodeFormat.DATAMATRIX
64 EnumDWT_BarcodeFormat.EAN_8
128 EnumDWT_BarcodeFormat.EAN_13
256 EnumDWT_BarcodeFormat.ITF
1024 EnumDWT_BarcodeFormat.PDF417
2048 EnumDWT_BarcodeFormat.QR_CODE
16384 EnumDWT_BarcodeFormat.UPC_A
32768 EnumDWT_BarcodeFormat.UPC_E
131072 EnumDWT_BarcodeFormat.INDUSTRIAL_25

To decode serveral kinds of barcode, you can simply set the value of format to the sum of the corresponding Numeric Values. Please refer to the example below.

//Decode the first image in buffer synchronously
//Support decoding code_39, code_128,QR code,2068 = 4+16+2048    
DWObject.Addon.Barcode.Read(0, 2068);

The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.

<function> optional optionalAsyncSuccessFunc(sImageIndex, result): callback function triggered when barcode reading succeeds.

Read the recoginition result here.

<function> optional optionalAsyncFailureFunc(errorCode, errorString);: callback function in case barcode reading fails.

Read the error message in this function.

Please refer to the function prototype OnBarcodeReadSuccess or OnBarcodeReadFailure.

Return value

Only valid when used synchronously or in the callback function optionalAsyncSuccessFunc.

<BarcodeResult> is returned when

  • the method is used synchronously.
  • in the callback optionalAsyncSuccessFunc(sImageIndex, result) when the method is used asynchronously.

Methods available in <BarcodeResult> object

Data Type Method Name Description
<long> GetErrorCode() Returns the error code. Same as DWObject.ErrorCode
<string> GetErrorString() Returns the error string. Same as DWObject.ErrorString
<long> GetCount() Returns how many barcodes are found in the specified image
<string> GetContent() Returns the barcode info in plain text or base64 string if the barcode represents binary data.
<int> GetFormat(index) Returns the format of one (specified by index) of the barcodes on one image.
<int> GetContentType(index) Returns the type of one (specified by index) of the barcodes on one image. 1 means binary, 0 means text.
<float> GetX1(index) Returns the X coordinate of the top-left point (as shown below) of one (specified by index) of the barcodes on one image.
<float> GetX2(index) Returns the X coordinate of top-right point (as shown below) of one (specified by index) of the barcodes on one image.
<float> GetX3(index) Returns the X coordinate of bottom-right point (as shown below) of one (specified by index) of the barcodes on one image.
<float> GetX4(index) Returns the X coordinate of bottom-left (as shown below) of one (specified by index) of the barcodes on one image.
<float> GetY1(index) Returns the Y coordinate of top-left point (as shown below) of one (specified by index) of the barcodes on one image.
<float> GetY2(index) Returns the Y coordinate of top-right point (as shown below) of one (specified by index) of the barcodes on one image.
<float> GetY3(index) Returns the Y coordinate of bottom-right point (as shown below) of one (specified by index) of the barcodes on one image.
<float> GetY4(index) Returns the Y coordinate of bottom-left (as shown below) of one (specified by index) of the barcodes on one image.

DWT_BarcodeSample

See also

Addon.Barcode.ReadRect()

Example

var GetBarcodeInfo = function(sImageIndex, result){
        var count = result.GetCount();
        if (count == 0) {
            alert("No barcode found.");
            return;
        } else {
            for (i = 0; i < count; i++) {
                var text = result.GetContent(i);
                var x = result.GetX1(i);
                var y = result.GetY1(i);
                var format = result.GetFormat(i);
                var barcodeText = ("barcode[" + (i + 1) + "]: " + text + " with ");
                barcodeText += ("format: " + format + " was found at \n");
                barcodeText += ("x: " + x + " y:" + y + "\n");
                alert(barcodeText);
            }
        }
    };
    var GetErrorInfo = function(errorcode, errorstring){
        alert(errorstring);
    }
    DWObject.Addon.Barcode.Read(0, EnumDWT_BarcodeFormat.CODE_39, GetBarcodeInfo, GetErrorInfo);
Is this page helpful?

Leave a Reply

Your email address will not be published.