Tcl Requires Chilkat v11.7.0+
Tcl
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 Tcl Downloads
load ./chilkat.dll
set success 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.
set bd [new_CkBinData]
set success [CkBinData_AppendEncoded $bd "000102030405FF00FE4368696C6B6174" "hex"]
if {$success == 0} then {
puts [CkBinData_lastErrorText $bd]
delete_CkBinData $bd
exit
}
set json [new_CkJsonObject]
CkJsonObject_UpdateString $json "payload.type" "binary"
CkJsonObject_UpdateString $json "payload.base64" [CkBinData_getEncoded $bd "base64"]
CkJsonObject_UpdateString $json "output.path" "qa_output/qr_binary.png"
CkJsonObject_UpdateBool $json "output.overwrite" 1
CkJsonObject_UpdateString $json "output.return" "none"
set fmt [new_CkFormats]
set jsonOut [new_CkJsonObject]
set success [CkFormats_QrCode $fmt "generate" $json $jsonOut]
if {$success == 0} then {
puts [CkFormats_lastErrorText $fmt]
delete_CkBinData $bd
delete_CkJsonObject $json
delete_CkFormats $fmt
delete_CkJsonObject $jsonOut
exit
}
puts "bytes given: [CkBinData_get_NumBytes $bd]"
puts "bytes encoded: [CkJsonObject_IntOf $jsonOut {symbols[0].payloadBytes}]"
puts "mode: [CkJsonObject_stringOf $jsonOut {symbols[0].selectedEncoding.mode}]"
puts "QR version: [CkJsonObject_IntOf $jsonOut {symbols[0].selectedEncoding.version}]"
# The image written to qa_output/qr_binary.png:
#
# Sample output:
# bytes given: 16
# bytes encoded: 16
# mode: byte
# QR version: 2
delete_CkBinData $bd
delete_CkJsonObject $json
delete_CkFormats $fmt
delete_CkJsonObject $jsonOut