PowerBuilder Requires Chilkat v11.7.0+
PowerBuilder
Generate a QR Code PNG in Memory
See more QR Code Examples
Demonstrates getting a QR code image without writing a file. With no output options the result is a PNG returned as base64 in outputs[0].base64 of the response. The example decodes it into a BinData, which holds the bytes of the PNG to send in an HTTP response, store in a database, attach to an email, or save.Chilkat PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Json
oleobject loo_Fmt
oleobject loo_JsonOut
oleobject loo_BdPng
li_Success = 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
if li_rc < 0 then
destroy loo_Json
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Json.UpdateString("payload.text","https://www.chilkatsoft.com/")
loo_Json.UpdateInt("render.moduleSize",6)
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_Json
destroy loo_Fmt
destroy loo_JsonOut
return
end if
Write-Debug "format: " + loo_JsonOut.StringOf("outputs[0].format")
Write-Debug "MIME type: " + loo_JsonOut.StringOf("outputs[0].mimeType")
Write-Debug "image: " + string(loo_JsonOut.IntOf("outputs[0].width")) + " x " + string(loo_JsonOut.IntOf("outputs[0].height")) + " pixels"
// outputs[0].base64 is the PNG file, base64 encoded.
loo_BdPng = create oleobject
li_rc = loo_BdPng.ConnectToNewObject("Chilkat.BinData")
li_Success = loo_BdPng.AppendEncoded(loo_JsonOut.StringOf("outputs[0].base64"),"base64")
if li_Success = 0 then
Write-Debug loo_BdPng.LastErrorText
destroy loo_Json
destroy loo_Fmt
destroy loo_JsonOut
destroy loo_BdPng
return
end if
Write-Debug "PNG bytes: " + string(loo_BdPng.NumBytes)
// The BinData holds the image. Here it is simply saved.
li_Success = loo_BdPng.WriteFile("qa_output/qr_in_memory.png")
if li_Success = 0 then
Write-Debug loo_BdPng.LastErrorText
destroy loo_Json
destroy loo_Fmt
destroy loo_JsonOut
destroy loo_BdPng
return
end if
// The PNG held in bdPng:
//
// Sample output:
// format: png
// MIME type: image/png
// image: 222 x 222 pixels
// PNG bytes: 877
destroy loo_Json
destroy loo_Fmt
destroy loo_JsonOut
destroy loo_BdPng