BarcodeDecoder QML Type

Capture, read and decode barcodes through image files. More...

Import Statement: import ArcGIS.AppFramework.Barcodes 1.0

Properties

Methods

Detailed Description

The BarcodeDecoder component provides specialized tools to read and decode a wide variety of barcode types. This component is specifically designed to be used with images, making a dedicated external barcode scanner unnecessary.

BarcodeDecoder works through scanning images, such as from a file or an image object, for valid barcodes. These images can then be edited or processed futher by other components or applications. Consider the BarcodeFilter component for faster detection through a video stream.

This code sample outlines the functions a barcode decoder to a pre-existing camera object. The camera takes a photo every quarter of a second, searching for a readable barcode. Once found, the image is captured and the barcode decoded.

Item {
    BarcodeDecoder {
        id: barcodeDecoder

        property int _decodeHints: BarcodeDecoder.DecodeHintQR_CODE
                                   | BarcodeDecoder.DecodeHintTryHarder

        property bool rotated: false
        property bool has1D: (decodeHints &
                             (BarcodeDecoder.DecodeHintCODABAR
                              | BarcodeDecoder.DecodeHintCODE_39
                              | BarcodeDecoder.DecodeHintCODE_93
                              | BarcodeDecoder.DecodeHintCODE_128
                              | BarcodeDecoder.DecodeHintEAN_8
                              | BarcodeDecoder.DecodeHintEAN_13
                              | BarcodeDecoder.DecodeHintITF
                              | BarcodeDecoder.DecodeHintMAXICODE
                              | BarcodeDecoder.DecodeHintRSS_14
                              | BarcodeDecoder.DecodeHintRSS_EXPANDED
                              | BarcodeDecoder.DecodeHintUPC_A
                              | BarcodeDecoder.DecodeHintUPC_E
                              | BarcodeDecoder.DecodeHintUPC_EAN_EXTENSION
                              )) !== 0

        decodeHints: _decodeHints

        onStatusChanged: {
            if (status === BarcodeDecoder.Error) {
                if (has1D && !rotated) {
                    imageObject.rotate(90, imageObject.width >> 1, imageObject.height >> 1);
                    rotated = true;
                    decode(imageObject.url);
                    return;
                }
                scanFailed();
                return;
            }

            if (status !== BarcodeDecoder.Decoding && barcode.length !== 0) {
                console.log("codeScanned:", barcode, "type:", barcodeTypeString)

                if (debugMode) {
                    scanMessage.show(barcodeTypeString + "\n" + barcode, 5000, "white");
                } else {
                    scanMessage.show(barcode, undefined, "green");
                    codeScanned(barcode);
                }
            }
        }
    }

    FileFolder {
        id: captureFolder

        path: AppFramework.standardPaths.writableLocation(StandardPaths.TempLocation)
    }

    Timer {
        id: retryTimer

        running: false
        repeat: false
        triggeredOnStart: false
        interval: 250

        onTriggered: {
            scan();
        }
    }

    function scan() {
        barcodeDecoder.clear();
        if (flashActive || scanMode === scanModeCapture) {
            scanCapture();
        }
    }

        function scanCapture() {
        camera.imageCapture.captureToLocation(captureFolder.filePath("code.jpg"));
    }

    function decodeCapture(path) {
        imageObject.load(path);
        var captureFrameD = Math.min(imageObject.size.width, imageObject.size.height) * 9/ 10;
        var captureFrameX = (imageObject.size.width - captureFrameD) >> 1;
        var captureFrameY = (imageObject.size.height - captureFrameD) >> 1;
        imageObject.clip(captureFrameX, captureFrameY, captureFrameD, captureFrameD);
        barcodeDecoder.rotated = false;
        barcodeDecoder.decode(imageObject.url);
    }
}

Enumerations

Status enumeration

Enum describing the decoder's potential states.

NameValue
BarcodeDecoder.Ready0
BarcodeDecoder.Decoding1
BarcodeDecoder.Error2

BarcodeType enumeration

Enum describing the type of barcode to scan for.

NameValue
BarcodeDecoder.BarcodeTypeNONE0
BarcodeDecoder.BarcodeTypeAZTEC1
BarcodeDecoder.BarcodeTypeCODABAR2
BarcodeDecoder.BarcodeTypeCODE_393
BarcodeDecoder.BarcodeTypeCODE_934
BarcodeDecoder.BarcodeTypeCODE_1285
BarcodeDecoder.BarcodeTypeDATA_MATRIX6
BarcodeDecoder.BarcodeTypeEAN_87
BarcodeDecoder.BarcodeTypeEAN_138
BarcodeDecoder.BarcodeTypeITF9
BarcodeDecoder.BarcodeTypeMAXICODE10
BarcodeDecoder.BarcodeTypePDF_41711
BarcodeDecoder.BarcodeTypeQR_CODE12
BarcodeDecoder.BarcodeTypeRSS_1413
BarcodeDecoder.BarcodeTypeRSS_EXPANDED14
BarcodeDecoder.BarcodeTypeUPC_A15
BarcodeDecoder.BarcodeTypeUPC_E16
BarcodeDecoder.BarcodeTypeUPC_EAN_EXTENSION17

DecodeHint enumeration

Enum describing the hints that are produced by the scanner to ensure a more accurate scan.

NameValue
BarcodeDecoder.DecodeHintTryHarder-2147483648
BarcodeDecoder.DecodeHintNONE1
BarcodeDecoder.DecodeHintAZTEC2
BarcodeDecoder.DecodeHintCODABAR4
BarcodeDecoder.DecodeHintCODE_398
BarcodeDecoder.DecodeHintCODE_9316
BarcodeDecoder.DecodeHintCODE_12832
BarcodeDecoder.DecodeHintDATA_MATRIX64
BarcodeDecoder.DecodeHintEAN_8128
BarcodeDecoder.DecodeHintEAN_13256
BarcodeDecoder.DecodeHintITF512
BarcodeDecoder.DecodeHintMAXICODE1024
BarcodeDecoder.DecodeHintPDF_4172048
BarcodeDecoder.DecodeHintQR_CODE4096
BarcodeDecoder.DecodeHintRSS_148192
BarcodeDecoder.DecodeHintRSS_EXPANDED16384
BarcodeDecoder.DecodeHintUPC_A32768
BarcodeDecoder.DecodeHintUPC_E65536
BarcodeDecoder.DecodeHintUPC_EAN_EXTENSION131072

Property Documentation

[read-only] barcode : string

Returns the string decoded from the last barcode scanned.


[read-only] barcodeType : BarcodeType

Returns the type of barcode the decoder is currently using.


[read-only] barcodeTypeString : string

Returns a human-readable string of the barcode type being scanned for.


boundingRect : rect

The rectangle to fit the barcode into.


decodeHints : int

Returns the number corresponding to the latest hint given by the decoder to return a more accurate scan.


[read-only] points : object

This property is currently not in use.


source : url

Returns the URL of the image that was the source of the barcode.


[read-only] status : Status

Returns the current status of the decoder.


Method Documentation

clear()

Clears the result, type, and points of barcode currently in use by the object.


decode(url source)

Decodes the barcode found in the defined source, presenting the contained string.

If a bounding rectangle is not present, the decoder will scan the entire image for a barcode. This is easier for the user to use, but is more likely to produce errors.

The source parameter

The URL path to the image providing the barcode.


decode(url source, rect boundingRect)

Decodes the barcode found in the defined source, presenting the contained string.

If a bounding rectangle is present, the decoder will only scan within the rectangle. This is slower to use, but more accurate.

The source parameter

The URL path to the image providing the barcode.

The boundingRect parameter

The bounding rectangle the decoder will scan for the barcode within.


string getBarcodeTypeString(barcodetype barcodeType_)

The barcodeType_ parameter


Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.