Sample code for 30+ languages & platforms
DataFlex Requires Chilkat v11.7.0+

QR Code with Binary Data

See more QR Code Examples

Demonstrates a QR code that holds arbitrary bytes rather than text. The payload type is binary and the bytes are given as base64 in payload.base64. Any byte value may be used, including zero. Keep in mind that many phone camera apps expect text, so binary payloads are for readers that you control.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoBd
    Variant vJson
    Handle hoJson
    Handle hoFmt
    Variant vJsonOut
    Handle hoJsonOut
    String sTemp1
    Integer iTemp1

    Move False To iSuccess

    //  This example requires the Chilkat API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.

    //  The bytes to encode.  Here they come from hex, but they could be loaded from a file with LoadFile.
    Get Create (RefClass(cComChilkatBinData)) To hoBd
    If (Not(IsComObjectCreated(hoBd))) Begin
        Send CreateComObject of hoBd
    End
    Get ComAppendEncoded Of hoBd "000102030405FF00FE4368696C6B6174" "hex" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoBd To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "payload.type" "binary" To iSuccess
    Get ComGetEncoded Of hoBd "base64" To sTemp1
    Get ComUpdateString Of hoJson "payload.base64" sTemp1 To iSuccess
    Get ComUpdateString Of hoJson "output.path" "qa_output/qr_binary.png" To iSuccess
    Get ComUpdateBool Of hoJson "output.overwrite" True To iSuccess
    Get ComUpdateString Of hoJson "output.return" "none" To iSuccess

    Get Create (RefClass(cComChilkatFormats)) To hoFmt
    If (Not(IsComObjectCreated(hoFmt))) Begin
        Send CreateComObject of hoFmt
    End
    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonOut
    If (Not(IsComObjectCreated(hoJsonOut))) Begin
        Send CreateComObject of hoJsonOut
    End
    Get pvComObject of hoJson to vJson
    Get pvComObject of hoJsonOut to vJsonOut
    Get ComQrCode Of hoFmt "generate" vJson vJsonOut To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFmt To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComNumBytes Of hoBd To iTemp1
    Showln "bytes given: " iTemp1
    Get ComIntOf Of hoJsonOut "symbols[0].payloadBytes" To iTemp1
    Showln "bytes encoded: " iTemp1
    Get ComStringOf Of hoJsonOut "symbols[0].selectedEncoding.mode" To sTemp1
    Showln "mode: " sTemp1
    Get ComIntOf Of hoJsonOut "symbols[0].selectedEncoding.version" To iTemp1
    Showln "QR version: " iTemp1

    //  The image written to qa_output/qr_binary.png:

    //  image

    //  Sample output:

    //  bytes given: 16
    //  bytes encoded: 16
    //  mode: byte
    //  QR version: 2


End_Procedure