Sample code for 30+ languages & platforms
Visual FoxPro 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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loBd
LOCAL loJson
LOCAL loFmt
LOCAL loJsonOut

lnSuccess = 0

*  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.
loBd = CreateObject('Chilkat.BinData')
lnSuccess = loBd.AppendEncoded("000102030405FF00FE4368696C6B6174","hex")
IF (lnSuccess = 0) THEN
    ? loBd.LastErrorText
    RELEASE loBd
    CANCEL
ENDIF

loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("payload.type","binary")
loJson.UpdateString("payload.base64",loBd.GetEncoded("base64"))
loJson.UpdateString("output.path","qa_output/qr_binary.png")
loJson.UpdateBool("output.overwrite",1)
loJson.UpdateString("output.return","none")

loFmt = CreateObject('Chilkat.Formats')
loJsonOut = CreateObject('Chilkat.JsonObject')
lnSuccess = loFmt.QrCode("generate",loJson,loJsonOut)
IF (lnSuccess = 0) THEN
    ? loFmt.LastErrorText
    RELEASE loBd
    RELEASE loJson
    RELEASE loFmt
    RELEASE loJsonOut
    CANCEL
ENDIF

? "bytes given: " + STR(loBd.NumBytes)
? "bytes encoded: " + STR(loJsonOut.IntOf("symbols[0].payloadBytes"))
? "mode: " + loJsonOut.StringOf("symbols[0].selectedEncoding.mode")
? "QR version: " + STR(loJsonOut.IntOf("symbols[0].selectedEncoding.version"))

*  The image written to qa_output/qr_binary.png:

*  image

*  Sample output:

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

RELEASE loBd
RELEASE loJson
RELEASE loFmt
RELEASE loJsonOut