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

B4X
Dim success As Boolean = False

'  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.
Dim bd As ChilkatBinData
bd.Initialize
success = bd.AppendEncoded("000102030405FF00FE4368696C6B6174", "hex")
If success = False Then
    Log(bd.LastErrorText)
    Return
End If


Dim json As ChilkatJsonObject
json.Initialize
json.UpdateString("payload.type", "binary")
json.UpdateString("payload.base64", bd.GetEncoded("base64"))
json.UpdateString("output.path", "qa_output/qr_binary.png")
json.UpdateBool("output.overwrite", True)
json.UpdateString("output.return", "none")

Dim fmt As ChilkatFormats
fmt.Initialize
Dim jsonOut As ChilkatJsonObject
jsonOut.Initialize
success = fmt.QrCode("generate", json, jsonOut)
If success = False Then
    Log(fmt.LastErrorText)
    Return
End If


Log("bytes given: " & bd.NumBytes)
Log("bytes encoded: " & jsonOut.IntOf("symbols[0].payloadBytes"))
Log("mode: " & jsonOut.StringOf("symbols[0].selectedEncoding.mode"))
Log("QR version: " & jsonOut.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