Sample code for 30+ languages & platforms
Visual Basic 6.0 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 Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
success = 0

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

Dim fmt As New ChilkatFormats
Dim jsonOut As New ChilkatJsonObject

'  Dark blue modules on a pale yellow background.
Dim json As New ChilkatJsonObject
success = json.UpdateString("payload.text","https://www.chilkatsoft.com/")
success = json.UpdateInt("render.moduleSize",6)
success = json.UpdateString("render.foreground","#1B3A6B")
success = json.UpdateString("render.background","#FFF8DC")
success = json.UpdateString("output.path","qa_output/qr_blue.png")
success = json.UpdateBool("output.overwrite",1)
success = json.UpdateString("output.return","none")
success = fmt.QrCode("generate",json,jsonOut)
If (success = 0) Then
    Debug.Print fmt.LastErrorText
    Exit Sub
End If

Debug.Print "colored: " & jsonOut.StringOf("outputs[0].path") & ", " & jsonOut.IntOf("outputs[0].byteCount") & " bytes"

'  The image written to qa_output/qr_blue.png:

'  image

'  The same modules on a fully transparent background.
Dim json2 As New ChilkatJsonObject
success = json2.UpdateString("payload.text","https://www.chilkatsoft.com/")
success = json2.UpdateInt("render.moduleSize",6)
success = json2.UpdateString("render.foreground","#1B3A6B")
success = json2.UpdateString("render.background.color","#FFFFFF")
success = json2.UpdateNumber("render.background.opacity","0")
success = json2.UpdateString("output.path","qa_output/qr_transparent.png")
success = json2.UpdateBool("output.overwrite",1)
success = json2.UpdateString("output.return","none")
success = fmt.QrCode("generate",json2,jsonOut)
If (success = 0) Then
    Debug.Print fmt.LastErrorText
    Exit Sub
End If

Debug.Print "transparent: " & jsonOut.StringOf("outputs[0].path") & ", " & 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:

'  image

'  Sample output:

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