Android Barcode Library

The Android barcode library provides functions for detecting barcodes in images on Android devices.

Including the Library

To include the library in your standalones, include the Android Barcode Library in the Inclusions pane of the standalone settings stack.

Including the library

Using the Library

The library defines a function barcodeLibraryDetect that takes an image and a comma separated list of barcode formats as parameters, returning an array of barcodes found in the image. If all barcode formats are to be detected, pass the empty string for the barcode format parameter.

The following barcode formats are recognized:

The following code is an example of detecting all barcode types in the image "snapshot":

local tBarcodesA
put barcodeLibraryDetect(the text of image "barcodes", empty) into tBarcodesA
repeat for each element tBarcodeA in tBarcodesA
    printBarcode tBarcodeA, "barcode display field"
end repeat

The Barcode Array

Detected barcodes are returned as an array with the following keys:

The following code is an example of printing a barcode to a field:

command printBarcode pBarcodeA, pFieldName
    put "Format:" && pBarcodeA["format"] & return after field pFieldName
    put "Value Format:" && pBarcodeA["value format"] & return after field pFieldName
    put "Raw Value:" && pBarcodeA["raw value"] & return after field pFieldName
    put "Display Value:" && pBarcodeA["display value"] & return after pFieldName
    if pBarcode["parsed value"] is an array then
        put printParsedBarcodeValue(pBarcode["parsed value"], pFieldName)
    end if
end printBarcode

The Parsed Barcode Value

A barcode's parsed value is represented as an array with keys for each attribute of the barcode. The keys of the array depend on the barcode format. For example a phone number will include the fields number and type.

The following code is an example of printing the parsed barcode value to a field.

function printParsedBarcodeValue pParsedBarcodeValueA, pFieldName
    put printArray(pParsedBarcodeValueA) & return after field pFieldName
end printParsedBarcodeValue

function printArray pArray, pIndent
    local tString
    repeat for each key tKey in pArray
        if pArray[tKey] is an array then
            put tKey & ":" & return & printArray(pArray[tKey], pIndent & "..") & return after tString
        else
            put tKey & ":" && pArray[tKey] & return after tString
        end if
    end repeat
    return tString
end printArray

The Barcode Snapshot

The barcodeLibraryDetect will also return a snapshot of any barcode detected. The snapshot is represented as an array, containing keys for the snapshot's pixels as well as its dimensions.

The following code displays the snapshot in a image:

command displayBarcodeSnapshot pSnapshotA, pImageName
    lock screen
    set the lockLoc of image pImageName to true
    set the width of of image pImageName to pSnapshotA["width"]
    set the height of of image pImageName to pSnapshotA["height"]
    set the imageData of image pImageName to pSnapshotA["pixels"]   
    unlock screen   
end displayBarcodeSnapshot