PowerBuilder Requires Chilkat v11.7.0+
PowerBuilder
QR Code Colors and Transparent Background
See more QR Code Examples
Demonstrates colored QR codes. render.foreground is the color of the dark modules and render.background the color behind them, each as #RRGGBB. Either can instead be an object with a color and an opacity from 0 to 1, and a background opacity of 0 gives a PNG with a transparent background to place over a page or a design. Readers need contrast: keep the modules clearly darker than whatever ends up behind them.Chilkat PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Fmt
oleobject loo_JsonOut
oleobject loo_Json
oleobject loo_Json2
li_Success = 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Fmt = create oleobject
li_rc = loo_Fmt.ConnectToNewObject("Chilkat.Formats")
if li_rc < 0 then
destroy loo_Fmt
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_JsonOut = create oleobject
li_rc = loo_JsonOut.ConnectToNewObject("Chilkat.JsonObject")
// Dark blue modules on a pale yellow background.
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateString("payload.text","https://www.chilkatsoft.com/")
loo_Json.UpdateInt("render.moduleSize",6)
loo_Json.UpdateString("render.foreground","#1B3A6B")
loo_Json.UpdateString("render.background","#FFF8DC")
loo_Json.UpdateString("output.path","qa_output/qr_blue.png")
loo_Json.UpdateBool("output.overwrite",1)
loo_Json.UpdateString("output.return","none")
li_Success = loo_Fmt.QrCode("generate",loo_Json,loo_JsonOut)
if li_Success = 0 then
Write-Debug loo_Fmt.LastErrorText
destroy loo_Fmt
destroy loo_JsonOut
destroy loo_Json
return
end if
Write-Debug "colored: " + loo_JsonOut.StringOf("outputs[0].path") + ", " + string(loo_JsonOut.IntOf("outputs[0].byteCount")) + " bytes"
// The image written to qa_output/qr_blue.png:
//
// The same modules on a fully transparent background.
loo_Json2 = create oleobject
li_rc = loo_Json2.ConnectToNewObject("Chilkat.JsonObject")
loo_Json2.UpdateString("payload.text","https://www.chilkatsoft.com/")
loo_Json2.UpdateInt("render.moduleSize",6)
loo_Json2.UpdateString("render.foreground","#1B3A6B")
loo_Json2.UpdateString("render.background.color","#FFFFFF")
loo_Json2.UpdateNumber("render.background.opacity","0")
loo_Json2.UpdateString("output.path","qa_output/qr_transparent.png")
loo_Json2.UpdateBool("output.overwrite",1)
loo_Json2.UpdateString("output.return","none")
li_Success = loo_Fmt.QrCode("generate",loo_Json2,loo_JsonOut)
if li_Success = 0 then
Write-Debug loo_Fmt.LastErrorText
destroy loo_Fmt
destroy loo_JsonOut
destroy loo_Json
destroy loo_Json2
return
end if
Write-Debug "transparent: " + loo_JsonOut.StringOf("outputs[0].path") + ", " + string(loo_JsonOut.IntOf("outputs[0].byteCount")) + " bytes"
// qa_output/qr_transparent.png, placed here over a checkerboard and over a colored page
// to show that whatever is behind the image shows through:
//
// Sample output:
// colored: qa_output/qr_blue.png, 1345 bytes
// transparent: qa_output/qr_transparent.png, 1377 bytes
destroy loo_Fmt
destroy loo_JsonOut
destroy loo_Json
destroy loo_Json2