PowerBuilder Requires Chilkat v11.7.0+
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Bd
oleobject loo_Json
oleobject loo_Fmt
oleobject loo_JsonOut
li_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.
loo_Bd = create oleobject
li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData")
if li_rc < 0 then
destroy loo_Bd
MessageBox("Error","Connecting to COM object failed")
return
end if
li_Success = loo_Bd.AppendEncoded("000102030405FF00FE4368696C6B6174","hex")
if li_Success = 0 then
Write-Debug loo_Bd.LastErrorText
destroy loo_Bd
return
end if
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateString("payload.type","binary")
loo_Json.UpdateString("payload.base64",loo_Bd.GetEncoded("base64"))
loo_Json.UpdateString("output.path","qa_output/qr_binary.png")
loo_Json.UpdateBool("output.overwrite",1)
loo_Json.UpdateString("output.return","none")
loo_Fmt = create oleobject
li_rc = loo_Fmt.ConnectToNewObject("Chilkat.Formats")
loo_JsonOut = create oleobject
li_rc = loo_JsonOut.ConnectToNewObject("Chilkat.JsonObject")
li_Success = loo_Fmt.QrCode("generate",loo_Json,loo_JsonOut)
if li_Success = 0 then
Write-Debug loo_Fmt.LastErrorText
destroy loo_Bd
destroy loo_Json
destroy loo_Fmt
destroy loo_JsonOut
return
end if
Write-Debug "bytes given: " + string(loo_Bd.NumBytes)
Write-Debug "bytes encoded: " + string(loo_JsonOut.IntOf("symbols[0].payloadBytes"))
Write-Debug "mode: " + loo_JsonOut.StringOf("symbols[0].selectedEncoding.mode")
Write-Debug "QR version: " + string(loo_JsonOut.IntOf("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
destroy loo_Bd
destroy loo_Json
destroy loo_Fmt
destroy loo_JsonOut