Xbase++ Requires Chilkat v11.7.0+
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oFmt
LOCAL oJsonOut
LOCAL oJson
LOCAL oJson2
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oFmt := CreateObject("Chilkat.Formats")
oJsonOut := CreateObject("Chilkat.JsonObject")
// Dark blue modules on a pale yellow background.
oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("payload.text", "https://www.chilkatsoft.com/")
oJson:UpdateInt("render.moduleSize", 6)
oJson:UpdateString("render.foreground", "#1B3A6B")
oJson:UpdateString("render.background", "#FFF8DC")
oJson:UpdateString("output.path", "qa_output/qr_blue.png")
oJson:UpdateBool("output.overwrite", 1)
oJson:UpdateString("output.return", "none")
nSuccess := oFmt:QrCode("generate", oJson, oJsonOut)
IF (nSuccess == 0)
? oFmt:LastErrorText
oFmt:destroy()
oJsonOut:destroy()
oJson:destroy()
RETURN
ENDIF
? "colored: " + oJsonOut:StringOf("outputs[0].path") + ", " + Str(oJsonOut:IntOf("outputs[0].byteCount")) + " bytes"
// The image written to qa_output/qr_blue.png:
//
// The same modules on a fully transparent background.
oJson2 := CreateObject("Chilkat.JsonObject")
oJson2:UpdateString("payload.text", "https://www.chilkatsoft.com/")
oJson2:UpdateInt("render.moduleSize", 6)
oJson2:UpdateString("render.foreground", "#1B3A6B")
oJson2:UpdateString("render.background.color", "#FFFFFF")
oJson2:UpdateNumber("render.background.opacity", "0")
oJson2:UpdateString("output.path", "qa_output/qr_transparent.png")
oJson2:UpdateBool("output.overwrite", 1)
oJson2:UpdateString("output.return", "none")
nSuccess := oFmt:QrCode("generate", oJson2, oJsonOut)
IF (nSuccess == 0)
? oFmt:LastErrorText
oFmt:destroy()
oJsonOut:destroy()
oJson:destroy()
oJson2:destroy()
RETURN
ENDIF
? "transparent: " + oJsonOut:StringOf("outputs[0].path") + ", " + Str(oJsonOut: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
oFmt:destroy()
oJsonOut:destroy()
oJson:destroy()
oJson2:destroy()