Sample code for 30+ languages & platforms
Visual FoxPro Requires Chilkat v11.7.0+

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loFmt
LOCAL loJsonOut
LOCAL loJson
LOCAL loJson2

lnSuccess = 0

*  This example requires the Chilkat API to have been previously unlocked.
*  See Global Unlock Sample for sample code.

loFmt = CreateObject('Chilkat.Formats')
loJsonOut = CreateObject('Chilkat.JsonObject')

*  Dark blue modules on a pale yellow background.
loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("payload.text","https://www.chilkatsoft.com/")
loJson.UpdateInt("render.moduleSize",6)
loJson.UpdateString("render.foreground","#1B3A6B")
loJson.UpdateString("render.background","#FFF8DC")
loJson.UpdateString("output.path","qa_output/qr_blue.png")
loJson.UpdateBool("output.overwrite",1)
loJson.UpdateString("output.return","none")
lnSuccess = loFmt.QrCode("generate",loJson,loJsonOut)
IF (lnSuccess = 0) THEN
    ? loFmt.LastErrorText
    RELEASE loFmt
    RELEASE loJsonOut
    RELEASE loJson
    CANCEL
ENDIF

? "colored: " + loJsonOut.StringOf("outputs[0].path") + ", " + STR(loJsonOut.IntOf("outputs[0].byteCount")) + " bytes"

*  The image written to qa_output/qr_blue.png:

*  image

*  The same modules on a fully transparent background.
loJson2 = CreateObject('Chilkat.JsonObject')
loJson2.UpdateString("payload.text","https://www.chilkatsoft.com/")
loJson2.UpdateInt("render.moduleSize",6)
loJson2.UpdateString("render.foreground","#1B3A6B")
loJson2.UpdateString("render.background.color","#FFFFFF")
loJson2.UpdateNumber("render.background.opacity","0")
loJson2.UpdateString("output.path","qa_output/qr_transparent.png")
loJson2.UpdateBool("output.overwrite",1)
loJson2.UpdateString("output.return","none")
lnSuccess = loFmt.QrCode("generate",loJson2,loJsonOut)
IF (lnSuccess = 0) THEN
    ? loFmt.LastErrorText
    RELEASE loFmt
    RELEASE loJsonOut
    RELEASE loJson
    RELEASE loJson2
    CANCEL
ENDIF

? "transparent: " + loJsonOut.StringOf("outputs[0].path") + ", " + STR(loJsonOut.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:

*  image

*  Sample output:

*  colored: qa_output/qr_blue.png, 1345 bytes
*  transparent: qa_output/qr_transparent.png, 1377 bytes

RELEASE loFmt
RELEASE loJsonOut
RELEASE loJson
RELEASE loJson2